jquery 必填項判斷表單是否為空的方法
更新時間:2008年09月14日 20:42:33 作者:
jquery 表單驗證,檢測表單是否為空
html頁面
<form onsubmit="if(confirm('確定好你所填寫的正確,不然會發(fā)錯!')) {return checkForm();}else{return false;}" >
<table >
<tr>
<td>選擇發(fā)送人<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市發(fā)送
</td>
</tr>
<tr>
<td>選擇發(fā)送人2<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市發(fā)送
</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>
復(fù)制代碼 代碼如下:
<form onsubmit="if(confirm('確定好你所填寫的正確,不然會發(fā)錯!')) {return checkForm();}else{return false;}" >
<table >
<tr>
<td>選擇發(fā)送人<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市發(fā)送
</td>
</tr>
<tr>
<td>選擇發(fā)送人2<font class="red">*</font></td>
<td>
<input type="text" name="sendto_type[]" id="sendto_type1" value="1" >按城市發(fā)送
</td>
</tr>
</table>
</form>
js代碼
復(fù)制代碼 代碼如下:
<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>
您可能感興趣的文章:
- js中判斷文本框是否為空的兩種方法
- 判斷PHP數(shù)組是否為空的代碼
- C#三種判斷數(shù)據(jù)庫中取出的字段值是否為空(NULL) 的方法
- Js判斷參數(shù)(String,Array,Object)是否為undefined或者值為空
- java判斷字符串String是否為空問題淺析
- js判斷為空Null與字符串為空簡寫方法
- JS判斷變量是否為空判斷是否null
- JavaScript判斷textarea值是否為空并給出相應(yīng)提示
- Shell腳本中判斷輸入變量或者參數(shù)是否為空的方法
- python使用any判斷一個對象是否為空的方法
- PHP判斷是否為空的幾個函數(shù)對比
- JS/Jquery判斷對象為空的方法
相關(guān)文章
jQuery實現(xiàn)鼠標劃過添加和刪除class的方法
這篇文章主要介紹了jQuery實現(xiàn)鼠標劃過添加和刪除class的方法,涉及jQuery鼠標事件及頁面樣式的相關(guān)操作技巧,需要的朋友可以參考下2015-06-06jquery預(yù)覽圖片實現(xiàn)鼠標放上去顯示實際大小
本文為大家介紹的這個示例為jquery實現(xiàn)的預(yù)覽圖片,當鼠標放上去顯示實際大小,感興趣的朋友可以學(xué)習(xí)下2014-01-01js和jQuery設(shè)置Opacity半透明 兼容IE6
對于每一個網(wǎng)站前端開發(fā)人員,常常都會遇到設(shè)置div透明度的需求,比如在實現(xiàn)圖片幻燈片切換效果經(jīng)常就需要使圖片淡入淡出。本文分別對原生js和jQuery在IE和其它瀏覽器中設(shè)置透明度的方法和相關(guān)注意事項進行總結(jié)。2016-05-05jQuery 實現(xiàn)左右兩側(cè)菜單添加、移除功能
本文通過實例代碼給大家分享了jQuery 實現(xiàn)左右兩側(cè)菜單添加、移除功能,需要的朋友參考下吧2018-01-01