我需要在输入字段中屏蔽一些数字。我在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)
谢谢
最佳答案
不应该var badWords = ['$mb1', "2222", "3333", "4444"];
是var badWords = ['<?php echo $mb1;?>', "2222", "3333", "4444"];
关于php - 使用jQuery阻止变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26454826/