Maison  >  Article  >  interface Web  >  JS分割字符串并放入数组的函数_javascript技巧

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

WBOY
WBOYoriginal
2016-05-16 18:05:031412parcourir
复制代码 代码如下:

var InterestKeywordListString = $("#userInterestKeywordLabel").html();

var InterestKeywordListArr = [];
var t = '';

for (var i = 0; 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;ialert(
InterestKeywordListArr[i]
);
}
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn