JS分割字符串并放入数组的函数


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]
);
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdfwyj.html