欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js 正则表达式 /g 火狐下bug 正则表达式IEFirefox.net

程序员文章站 2022-06-11 10:21:40
...
<html>
<body>
<script type="text/javascript">
function isNumeric(strValue)
{
    return /^\d*$/g.test(strValue);
}
function isNumeric1(strValue)
{
    return /^\d*$/.test(strValue);
}
strValue = '1000'
document.writeln(isNumeric(strValue)); // true
document.writeln(isNumeric(strValue)); // firefox: false;  IE:true
document.writeln('<br/>')
document.writeln(isNumeric1(strValue)); // true
document.writeln(isNumeric1(strValue)); // true
document.writeln('<br/>')
document.writeln(/^\d*$/g.test(strValue)); // true
document.writeln(/^\d*$/g.test(strValue));// true
</script>
</body>
</html>
原因分析见:http://www.jb51.net/article/18334.htm