jQuery表单提交委托

时间:2013-11-01 11:20:05

标签: php jquery

我有一个工作的jquery代码:

  • 从具有相同身份的多个表单提交特定表单
  • 在textarea上做一些验证,禁用提交。
  • 明文并在成功或失败时显示消息。

但是 - 我有问题显示消息,没有输入文本时的验证消息正确显示给特定的表格div。但是成功/失败消息没有显示给特定的div,它总是显示给第一个表格div。

$('input[type="submit"]').attr('disabled','disabled');
 $('#replytext').keyup(function() {
    if($('#replytext').val() != '') {
       $('input[type="submit"]').removeAttr('disabled');
    }
 });
    $(document).ready(function(){
        //$("#replyForm").submit( function () {
        $('#profile-posts-updates').delegate('#replyForm', 'submit', function() {
        //if($(this).find('#replytext').val()=='')
        if(jQuery(this).children("#replytext").val()=='') {  $(this).next('#replyerror').html('Write your message to post!').css("color","red"); return false;}
         //$('#imgbtn').show();
         //$('#post').hide();
          $.post(
           'Process.php?in=DataHandler',
            $(this).serialize(),
            function(data){
            if(data === 'Success'){
                $('#replytext').val('');
                //jQuery(this).children("#replytext").val('');
                //$("#postbox").fadeOut(50);
                //$("#postbtn").fadeIn(400);
                $("#replyerror").html('Your message has been successfully posted !').css("color","green");
                //$(this).children("#replyerror:first").html('Write your message to post!').css("color","red");
                }else{
                $("#replyerror").html('There was some problem please try again!').css("color","red");
                }
            //$('#imgbtn').hide();
            //$('#post').show();
            }
          );
          return false;   
        });   
    });

1 个答案:

答案 0 :(得分:1)

这是你的问题所在(部分)

“具有相同ID的多个表单”

每个HTML DOM元素必须具有唯一ID,否则它无效HTML