现在的位置: 首页 > 综合 > 正文

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

2012年03月04日 ⁄ 综合 ⁄ 共 458字 ⁄ 字号 评论关闭

复制代码 代码如下:
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]
);
}

抱歉!评论已关闭.