想判断表单是否为空,如果失去焦点后表单为空的话,后面的label显示“账号不能为空”,但是么反应,下面是代码,大家帮我看看吧<script type="text/javascript">
function chkAccount(){
var val=document.getElementsByName("account").value;
if(val=""){
document.getElementById("alert_account").innerHTML="账号不能为空";
form.account.focus();
return false;
}
}
</script><form action="register_check.php" method="post" name="form">
<div class="attribute account">
<label for="person_account">账号</label><br />
<input id="person_account" name="account" size="30" type="text" onblur="return chkAccount()"/>
<label id="alert_account"></label>
</div>
</form>
function chkAccount(){
var val=document.getElementsByName("account").value;
if(val=""){
document.getElementById("alert_account").innerHTML="账号不能为空";
form.account.focus();
return false;
}
}
</script><form action="register_check.php" method="post" name="form">
<div class="attribute account">
<label for="person_account">账号</label><br />
<input id="person_account" name="account" size="30" type="text" onblur="return chkAccount()"/>
<label id="alert_account"></label>
</div>
</form>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货