JS分割字符串并放入数组的函数: var InterestKeywordListString = $("#userInterestKeywordLabel").html(); var InterestKeywordListArr = []; var t = ''; for (var i = 0; i < InterestKeywordListString.length; i++) { var tmp = InterestKeywordListString.charAt(i); …
方法1: var str = ' h t m l 5 '; function trim(str) { var reg = /(\s+)/g; var m,s = str; while(m = reg.exec(s)){ s = s.replace(m[1],""); } return s; } str = trim(str); console.log(str); //html5 方法2: var str = ' h t m l 5 c s s 3'; function trim(str…