JS中如何将一组字符或者数值转换成数组? 比如:001002003这一串字符,装换成a["001","002","003"]这种形式的,可以每三位是一个数组值,请问各位高手能实现么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var s = "001002003"var re = new RegExp(".{3}","g")var a = []while ((n=re.exec(s)) != null){ a[a.length] = n[0]}for(i in a) alert(a[i]) <script type="text/javascript">var test = "0010020034";var arrTest = [];var item = "";for (var index = 0; index < test.length; index++) { item = item + test.charAt(index); if (((index + 1) % 3 == 0 && item.length > 0) || index == test.length - 1) { arrTest.push(item); item = ""; }}for (var index = 0; index < arrTest.length; index++) { alert(arrTest[index]);}</script> var s = "001002003"var reg=/\d{3}/g;alert(s.match(reg)) 完善下,不足3个数的显示var s = "00100200343"var reg=/\d{3}|\d{2}|\d{1}/g;alert(s.match(reg)) <script>var s="00100200343";alert(s.match(/\d{3}|\d+$/g));</script> IE 下滚动条问题 有Javascript 2代的消息么? 网页浮动窗口防360屏蔽 ---如何判断我所输入的数据是否满足以下要求---- 如何当选中一个单选按钮时,使某个文本框不能输入 如何避开提示框直接关闭窗口(window.close();)? 100分求表单处理代码,各位请进! 超级入门问题! JavaScript 选择题功能 js图片旋转且充满div问题 javascript如何调用本地txt中的数据 getElementById失效,变成byName了.疑惑中,高手进---
var s = "001002003"
var re = new RegExp(".{3}","g")
var a = []
while ((n=re.exec(s)) != null){
a[a.length] = n[0]
}
for(i in a) alert(a[i])
var test = "0010020034";
var arrTest = [];
var item = "";
for (var index = 0; index < test.length; index++) {
item = item + test.charAt(index);
if (((index + 1) % 3 == 0 && item.length > 0) || index == test.length - 1) {
arrTest.push(item);
item = "";
}
}for (var index = 0; index < arrTest.length; index++) {
alert(arrTest[index]);
}</script>
var reg=/\d{3}/g;
alert(s.match(reg))
var s = "00100200343"
var reg=/\d{3}|\d{2}|\d{1}/g;
alert(s.match(reg))
var s="00100200343";
alert(s.match(/\d{3}|\d+$/g));
</script>