一个JavaScript用逗号分割字符串实例
//用逗号隔开字符串成数组打印。 <!doctypehtml> <htmllang="en"> <head> <metacharset="utf-8"> <title>每天一个JavaScript实例-分割字符串</title> <script> window.onload=function(){ varkeywordList=prompt("输入字符,用","分开"); vararrayList=keywordList.split(",",2); console.log(arrayList); varresultString=""; for(vari=0;i<arrayList.length;i++){ resultString+="keyword:"+arrayList[i]+"<br/>"; } varaaa=document.getElementById("result"); aaa.innerHTML=resultString; } </script> </head> <body> <divid="result"></div> </body> </html>