0
我有这样的形式:禁用提交按钮JavaScript时触发
<form action = "" method = "post">
<input type = "text" name = "tbox_phone" placeholder = "phone" onkeyup="checker_phone(this.value)">
<div id = "msg"></div>
<input type = "submit" name = "button_submit" value = "submit">
</form>
的checker_phone
连接到通过其他PHP页面运行的脚本。
脚本:
<script>
function checker_phone(val)
{
$.ajax ({
type:"POST",
url:"check_phone.php",
data:'phone='+val,
success: function(data){
$("#msg").html(data);
}
});
}
</script>
PHP页面:
$phone = htmlentities($_POST['tbox_phone']);
$var_phone= mysqli_real_escape_string($connect,$phone);
$search= "SELECT * FROM users WHERE phone= '$var_phone' ";
$exec= mysqli_query($connect,$search);
$count = mysqli_num_rows($exec);
if($count==1) {
echo "that phone number is already registered";
}
上面的代码工作。现在,我想要禁用提交按钮,只要php的计数结果返回1.有什么办法可以做到这一点?
Javascript是好的,但我更喜欢简单的,而不是长而复杂的脚本。
开始ajax开机自检之前,加的残疾人属性按钮,然后在成功移除已停用的属性 – Akintunde007
'$( '输入[名称= button_submit]') .prop('disabled',data ==“该电话号码已经注册了)' – guradio
你在提交过程中使用了ajax吗? –