经测试代码如下:
/**
* 分割字符串并放入数组
*
* @param
* @arrange (512.笔记) jb51.cc
**/
var InterestKeywordListString = $("#userInterestKeywordLabel").html();
var InterestKeywordListArr = [];
var t = '';
for (var i = 0; i < InterestKeywordListString.length; i++) {
var tmp = InterestKeywordListString.charAt(i);
if (tmp != '' && tmp != ',') {
t += tmp;
lastNum = true;
} else {
if (t != '' && t != ',') {
InterestKeywordListArr.push(t);
t = '';
}
lastNum = false;
}
}
if (t != '' && t != ',') {
InterestKeywordListArr.push(t);
}
for(var i=0;i<InterestKeywordListArr.length;i++){
alert(
InterestKeywordListArr[i]
);
}
// 来自:编程之家 jb51.cc(jb51.cc)
原文链接:https://www.f2er.com/js/527752.html