我需要在输入字段中阻止一些数字。我在mysql表中得到了阻塞的数字:
id|number
1 |1234
2 |3456
我尝试了什么:
<?
include("connect.php");
$mb1=GetRow("SELECT number FROM mblock WHERE id=1");
$mb2=GetRow("SELECT number FROM mblock WHERE id=2");
?>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.4.2'></script>
<input type="text" placeholder="write here" />
Number to block:<?echo $mb1;?>
<p></p>
<script>
var badWords = ['$mb1', "2222", "3333", "4444"];
$("input").keyup(function(){
for(var i = 0; i < badWords.length; i++)
{
if(this.value == badWords[i])
{
this.value ="";
return;
}
}
})
</script>
.php正在检索号码,但没有阻止。其他数字是阻塞(2222,3333,4444)
THX
答案 0 :(得分:2)
不应该var badWords = ['$mb1', "2222", "3333", "4444"];
是var badWords = ['<?php echo $mb1;?>', "2222", "3333", "4444"];
答案 1 :(得分:0)
您确定在您的html文件中包含了jQuery库吗?