从textarea中空格、逗号、换行转换为逗号分隔的字符串 js string.split

时间:2023-01-03 19:34:30



    // 空白(空格、换行、tab)和逗号分隔的字符串,变成用逗号分隔
function getSplitString(str) {
var arr = str.split(",");

var resources = "";
for (var i = 0; i < arr.length; i++) {
var arr1 = arr[i].split(/\s+/);

for (var j = 0; j < arr1.length; j++) {
if (jQuery.trim(arr1[j]) != "") {
resources += jQuery.trim(arr1[j]) + ",";
}
}
}

return resources;
}