拆分字符串?
将
var str= '1,张三,2,李四,3,王麻子 '
拆分成:
var str1=1,2,3
var str2=张三,李四,王麻子
------解决方案-------------------- <script language= "javascript ">
<!--
var str= '1,张三,2,李四,3,王麻子 ';
var str1= " ";
var str2= " ";
var cArray = new Array();
cArray = str.split( ', ');
for(var i=0;i <cArray.length;i++)
{
if(i%2 == 0)
{
str1 += cArray[i] + ", ";
}
else
{
str2 += cArray[i] + ", ";
}
}
str1 = str1.substring(0,str1.length-1);
str2 = str2.substring(0,str2.length-1);
document.write(str1+ " <br> ");
document.write(str2);
//-->
</script>
测试过了.没完题