Php jQuery表单随委托提交

Php jQuery表单随委托提交,php,jquery,Php,Jquery,我有一个可以工作的jquery代码: 从具有相同id的多个表单提交特定表单 在textarea上执行一些验证,禁用提交 清除文本并显示成功或失败消息 但是-我在显示消息时遇到问题,没有输入文本时的验证消息正确显示到特定表单div。但是成功/失败消息没有显示到特定div,它总是显示到第一个表单div $('input[type="submit"]').attr('disabled','disabled'); $('#replytext').keyup(function() { if(

我有一个可以工作的jquery代码:

  • 从具有相同id的多个表单提交特定表单
  • 在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;   
        });   
    });
这就是你的问题所在

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


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

具有相同ID的多个表单
->ID属性在整个DOM中应该是唯一的。但我相信使用jquery可以解决这个问题(解决方法?)。由于mysql while循环动态创建表单,因此很难为每个表单提供表单id,也很难创建jquery函数。任何帮助都将被apricated。@user2944727,对于无效标记没有“变通方法”。每个
id
必须是唯一的,否则,请使用
class
。顺便说一句,jQuery将只识别
id
的第一个实例。