关于在网页中使用正则表达式出现的问题!
function check()
{
var str = document.getElementById( "TextInput ").value;
var reg = /[a]{2};
if( reg.exec(str))
alert( "OK ");
else
alert( "no ");
}
</script>
</head>
<body>
<form method= "post ">
<input name= "Text1 " id= "TextInput " type= "text " size= "100 " value= "asdfasdfadsadsaadfdfasdfwefwefwefaafewef "/>
<br/>
<input name= "Button1 " type= "button " value= "按钮 " onclick= "check() " />
</form>
</body>
</html>
---点击按钮后就报错:缺少对象!
------解决方案--------------------少了一个斜线
------解决方案--------------------var reg = /[a]{2}/;
------解决方案--------------------就像字符串要用两个引号引起来一样...
正则要用两个/引起来,后面跟正则选项...
比如
var r = /\d+/ig;
------解决方案--------------------说的没错,所有的正则应该这样写
var dd=/表达式/;