请帮忙看一小段代码在 Google Chrome 里不工作
代码在 Firefox 和IE 里都正常,就是在 Google Chrome 不工作。
很郁闷啊! 代码兼容的问题,请帮忙看看吧,谢谢了!!!!!!
<span id="abc"> 100,000,000 </span>
<script>
function formatNumber(num){
if(!/^(\+|-)?(\d+)(\.\d+)?$/.test(num)){
return num;
}
var a = RegExp.$1,b = RegExp.$2,c = RegExp.$3;
var re = new RegExp().compile("(\\d)(\\d{3})(,|$)");
while(re.test(b)){
b = b.replace(re,"$1,$2$3");
}
return a +""+ b +""+ c;
}
window.onload = function ()
{
var oo=document.getElementById('abc');
var i = 235000000;
i=i+2;
setInterval(updateNum, 500);
updateNum();
function updateNum()
{
stri = formatNumber(i);
i=i+37;
oo.innerHTML = stri;
}
}
</script>
------解决方案--------------------直接这样就行了吧。。用compile干嘛
//var re = new RegExp().compile("(\\d)(\\d{3})(,
------解决方案--------------------
$)");
//===>
var re = new RegExp("(\\d)(\\d{3})(,
------解决方案--------------------
$)");
w3school.com.cn给出的示例compile有2个参数
http://www.w3school.com.cn/js/jsref_regexp_compile.asp