jquery验证提交

时间:2013-08-26 18:55:52

标签: jquery validation

有人可以帮助进行此验证吗?

$("#frm").submit(function() {
  $('#mailtoperson').each(function() {
    if ($(this).val() == '') {           
      $('#wizard').smartWizard('showMessage','Please check OK and YES once the email is ready to send');
    }
  });

 if ($('#mailtoperson').size() > 0) {
    $('#wizard').smartWizard('showMessage','Please complete the required field.');
    return false;
  }
})

基本上我的'#frm'带有textarea'#mailtoperson'和onsubmit我想验证'#mailtoperson'是否为空,如果是想要一条“pls complete”消息,如果有数据,那么我希望填充“pls check ok”消息。

编辑:

这似乎可以触发空白字段功能:

$('#frm').submit(function()
{
    if( !$(this).val() ) {
          $('#wizard').smartWizard('showMessage','Please complete');

}

这适用于简单的提交消息

$('#frm').submit(function() {
$('#wizard').smartWizard('showMessage','Please check OK and YES once the email is ready to send');
})

});

但他们不能一起工作 - 即如果空白则请填写,如果不是空白,请检查确定'...

2 个答案:

答案 0 :(得分:3)

$("#frm").submit(function() {
    if($('#mailtoperson').val().length == 0 ) {
        $('#wizard').smartWizard('showMessage','Please complete...');
    } else {
        $('#wizard').smartWizard('showMessage','pls check ok...');
    }
});

答案 1 :(得分:0)

使用if / else语句,也不需要循环,因为只有一个元素具有该id:

$("#frm").submit(function() {
  if($('#mailtoperson').val().trim() == '') {           
      $('#wizard').smartWizard('showMessage','Please check OK and YES once the email is ready to send');
  }else{
      $('#wizard').smartWizard('showMessage','Please complete the required field.');
  }
  return false;
});
相关问题