$(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()==" ")吗,如果有人有标准的检查,请提前提供help.thank。
发布于 2013-05-21 16:37:34
如果是表单提交,return true将允许表单在稍后执行javascript时提交表单,并且return false不会在javascript之后提交表单
现在关于jQuery验证,是的,您可以使用if($(".class").val()=='')进行空或非选择
发布于 2013-05-21 16:39:32
在if条件中,在出现错误消息后,可以使用return false来避免表单提交。
if($(".block").val()=="")如果您的第一个选项值为空,则上面的代码将起作用。
发布于 2013-05-21 16:42:56
您可以这样做:
$(".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;
});https://stackoverflow.com/questions/16665473
复制相似问题