html頁面
代碼如下:
<form onsubmit="if(confirm('確定好你所填寫的正確,不然會發錯!')) {return checkForm();}else{return false;}" >
<table >
<tr>
<td>選擇發送人<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市發送
</td>
</tr>
<tr>
<td>選擇發送人2<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市發送
</td>
</tr>
</table>
</form>
js代碼
代碼如下:
<script>
function checkForm() {
pass = true;
$("td:contains('*')").next().find("input").each(function(){
if(this.value == '') {
text = $(this).parent().prev().text();
alert(text+"是必填項");
this.focus();
pass = false;
return false;//跳出each
}
});
return pass;
}
</script>