0

我有一个使用 Jquery 显示消息的表单

*字段必填错误消息

如果表单已提交,我试图让它显示成功消息。

只要填写了 req 字段,表单就会提交。

如果填写了所有“req”字段,有谁知道我如何修改此代码以显示“成功”div?

谢谢

    $(function() {
       function validateform() {
          var valid = true;
          $(".req").css("border","1px solid #ccc");
          $(".req").each(function() {
             if ( $(this).val() == "" || $(this).val().replace(/\s/g, '').length == 0 ) {
                $(this).css("border","1px solided");$(".required").css("display","block");
                valid = false;
             }
          });
          return valid;
       }    
       $("#submit").click( function() {
          $('#myform').submit( validateform );
          $('$name').submit();
       });  
   });
4

3 回答 3

1
           submitHandler: function(form){
                  $(form).ajaxSubmit({
    target: '#preview', 
    success: function() {  
    $('#form id').slideDown('slow'),
<!-- RESET THE FORM FIELDS AFTER SUBMIT STARTS HERE-->
    $("#form")[0].reset();
<!--RESET THE FORM FIELDS AFTER SUBMIT  ENDS HERE--->
    } 

}); 

                }
于 2014-12-10T10:20:11.630 回答
0
    $(function() {
           function validateform() {
              var valid = true;
              $(".req").css("border","1px solid #ccc");
              $(".req").each(function() {
                 if ( $(this).val() == "" || $(this).val().replace(/\s/g, '').length == 0 ) {
                    $(this).css("border","1px solided");
                    $(".required").css("display","block");
                    valid = false;
                 }

              });
              return valid;
           }    
           $("#submit").click( function() {
              $('#myform').submit(function()

               {
               if( validateform)
              {
                $('$name').submit();
             }
         } );

           });  
       });

参考提交

于 2013-10-15T04:09:34.440 回答
0

There are two simple ways that will allow you to render a success message. You can either use ajax with the callback success function, or if you want a full post, you you can check at the top of your file if a certain POST was set, and if so, render a success message.

Here is an example of checking POST:

if(isset($_POST['name attribute posting'])) {
    $util->showSuccessMessage();
    //OR echo "<div class='popup'></div>"
}

And here is an example of using Ajax's success callback function:

function submitForm() {
    $.ajax({
        url : 'this_file.php',
        type: 'POST',
        success : showSuccessMessage   //function call
    })
}
于 2013-10-15T03:55:19.523 回答