日期:2014-05-16  浏览次数:20394 次

javascript判断表单不能为空!
<div class="biaodan">
        	<h3>(以下<font color="red">*</font>为必填项)</h3>
            <div class="bdnr">
			<form name="contactForm" method="post" action="/mail.php"  onsubmit="return check()" >
            	<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
                  <tr>
                    <td align="right">联系人<font color="red">*</font></td>
                    <td><input name="q1" type="text" /></td>
                  </tr>
                  <tr>
                    <td align="right">联系电话<font color="red">*</font></td>
                    <td><input name="q2" type="text" /></td>
                  </tr>
				  <tr>
                    <td align="right">地  区<font color="red">*</font></td>
                    <td><input name="q3" type="text" /></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td><input name="submit" type="submit" value="提交申请" class="icon" ></td>
                  </tr>
                </table>
			</form>
            </div>
        </div>
<!--by:xue-->
		<script language="javascript">
function check()
{
if(document.contactForm.q1.value=="")
{
alert("联系人不能为空!");
this.contactForm.q1.focus();
return false;
}
else if(document.contactForm.q2.value=="")
{
alert("电话不能为空!");
this.contactForm.q2.focus();
return false;
}
else if(document.contactForm.q3.value=="")
{
alert("地区不能为空!");
this.contactForm.q3.focus();
return false;
}
else contactForm.submit();
}
</script>