JS 小工具 MYSQL WHERE IN条件 去掉换行符(列转行)
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>MYSQL_WHERE_IN_去掉换行符(列转行)</title> <style type="text/css"> textarea { width: 1000px; height: 500px; } button { height: 50px; display: block; margin-top: 10px; width: 1000px; } </style> </head> <h3>MYSQL_WHERE_IN_去掉换行符(列转行)</h3> <textarea placeholder="源数据为列类型 如 106873O19050704439680 106873O19050889570315 106873O19051061114684 106873O19051061116360 106873O19051061118893 106873O19051138701262 106873O19051138702715 106873O19051138704386 106873O19051138705671 转换之后为 106873O19050704439680,106873O19050889570315,106873O19051061114684,106873O19051061116360,106873O19051061118893,106873O19051138701262,106873O19051138702715,106873O19051138704386,106873O19051138705671 勾选字符串类型,转换之后为 '106873O19050704439680','106873O19050889570315','106873O19051061114684','106873O19051061116360','106873O19051061118893','106873O19051138701262','106873O19051138702715','106873O19051138704386','106873O19051138705671' " id="input"> </textarea> <br> <input id="isStr" type="checkbox">字符串类型 <button id="btn">转</button> <div id="result"></div> <body> <script type="text/javascript"> /** * MYSQL_WHERE_IN_去掉换行符(列转行) * 2019/11/21 */ document.getElementById("btn").addEventListener('click', handler); function handler() { // dom let inputDom = document.getElementById('input'); let isStrDom = document.getElementById('isStr'); let resultDom = document.getElementById('result'); let val = inputDom.value; let isStr = isStrDom.checked; if (!val) { return; } // 替换换行符 let regexp = /[\r\n]/g; let replacer = isStr ? '\",\"' : ","; val = val.replace(regexp, replacer); if (isStr) { val = '"' + val + '"'; } resultDom.innerHTML += "<br>" + val + "<br>"; } </script> </body> </html>