数组过滤提交表单的多个关键字-重宇科技帮您办
时间:2013-1-12 编辑:邢台网络公司
//===================================================================
用数组是肯定的,关键是.indexof方法.
<html>
<head>
<meta http-equiv="Content-Type" c>
<title></title>
<script language="JavaScript">
var myarray = new Array("广告","色情","垃圾");
function check(theForm) {
for (i=0;i<myarray.length;i++) {
if (theForm.name.value.indexOf(myarray)!=-1)
// if (theForm.name.value == myarray)
{alert("本站禁止发布广告!");
return false;}
}
}
</script>
</head>
<body>
<form method="post" action="#">
<input value="" type="text" name="name">
<input type="submit" name="Submit" value="提交" >
</form>
</body>
</html>
//===================================================================
用正则更有效率
<html>
<head>
<meta http-equiv="Content-Type" c>
<title></title>
<script language="JavaScript">
var kws = "广告|色情|垃圾";
function check(theForm)
{
if (eval("/"+kws+"/gi.test(theForm.name.value)"))
{alert("本站禁止发布广告!"); return false;}
return true;
}
</script>
</head>
<body>
<form method="post" action="#">
<input value="" type="text" name="name">
<input type="Submit" name="Submit" value="提交" >
</form>
</body>
</html>
<<1
>>