我还帮你测试了一下,也觉得奇怪,隔一次true一次:
<script> 
var reg = /^\d*$/ig; 
document.write( reg.test( "123" ) ); 
document.write( reg.test( "123" ) ); 
document.write( reg.test( "123" ) ); 
document.write( reg.test( "123" ) ); 
document.write( reg.test( "123" ) ); 
</script> 

解决方案 »

  1.   

    http://topic.csdn.net/u/20070327/15/d4b4197d-35b9-452d-adb2-abeedf859b5a.html看 7 ,8 楼的回答
      

  2.   


    <script type="text/javascript"> 
    var reg = /^\d*$/ig; document.write("Match from : ")
    document.write(reg.lastIndex+"<br>");
    document.write("The result is : ");
    document.write(reg.test( "123")+"<br>"); 
    document.write("Since you use the g Mode,then the next match will start from : ")
    document.write(reg.lastIndex+"<br>");
    document.write("Then the result is : ")
    document.write(reg.test( "123")+"<br>"); 
    document.write("And Finally the Match index will be reset to :");
    document.write(reg.lastIndex);document.write("<br><br>");
    //Set the init Match index
    reg.lastIndex = 3;
    document.write("the reseted Match index is :");
    document.write(reg.lastIndex+"<br>");
    document.write("So the result will be : ")
    document.write(reg.test( "123")+"<br>"); </script>