[英]jquery validation checks not working properly
$(document).ready(function(){
$(".submit").click(function(){
if($('.disrtrict')[0].selectedIndex<=0){
$("#error1").html("district field is empty");
}
if($(".block")[0].selectedIndex<=0){
$("#error2").html("block field is empty");
}
if($(".village")[0].selectedIndex<=0){
$("#error3").html("village field is empty");
}
});
});
上面是我的jquery腳本。我是jquery的新手,並嘗試學習jquery。 我的問題是我使用return false.what返回true和false的概念,我使用if($(".block")[0].selectedIndex<=0)
我們可以使用if($(".block").val()==" ")
如果有人有標准支票,請提前提供幫助。謝謝。
如果它的表單提交return true
將允許表單提交表單以后執行javascript並return false
將不會在javascript之后提交表單
現在關於jQuery驗證,是的,您可以使用if($(".class").val()=='')
進行空或非選擇
在if條件中,在錯誤消息之后,您可以使用return false來避免表單提交。
if($(".block").val()=="")
如果您的第一個選項值為空,則上述代碼將起作用。
你可以這樣做:
$(".submit").click(function () {
if ($('.disrtrict').val() === '') {
$("#error1").html("district field is empty");
return false;
}
if ($(".block").val() === '') {
$("#error2").html("block field is empty");
return false;
}
if ($(".village").val() === '') {
$("#error3").html("village field is empty");
return false;
}
return true;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.