oninput實(shí)時(shí)判斷input框里面的值是不是符合要求
<style>
span{
display: none;
color: red;
margin:0 auto 15px;
width: 300px;
}
</style>
<input id="mobile" name="mobile" required="required" type="number" placeholder="請(qǐng)輸入賬號(hào)" oninput="check()" />
<script>
<span class="isphone">請(qǐng)輸入正確的11位手機(jī)號(hào)碼</span>
// 判斷手機(jī)號(hào)是不是11位
function check() {
var mobile = $("#mobile").val();
if(mobile.length>11){
mobile=mobile.slice(0,11)
}
if(mobile.length==11){
$(".code_message").attr("onclick", "sendMessage()");
$(".code_message").css("background", "#5E7CDC");
$('.isphone').css('display','none')
}else{
$(".code_message").removeAttr("onclick")
$('.isphone').css('display','block')
}
}
</script>
在form表單中使用button時(shí)镇眷,使用input type=button