首页 > 解决方案 > jquery 不在 IE、EDGE 和 FIREFOX 中工作,但在 CHROME 中工作

问题描述

我有一个表格

<form method="POST" action="">
  <div class="commentdiv">
    <input type="hidden" name="id" id="id" class="id" value="<?php echo $pixid;?>">
    <input type="hidden" name="username" id="username" value="<?php echo $activeusername;?>">
    <input type="hidden" name="uid" id="uid" value="<?php echo $id3;?>">
    <textarea style="" name="comment" id="comment" class="comment" placeholder="  comment here"></textarea>
    <button type="button" style="background-color: Transparent; background-repeat:no-repeat; border: none; cursor:pointer; overflow: hidden; color: #3897f0; font-weight:600;"class="submit">
      comment
    </button>
  </div>
</form>

这是我的 javascript

$(document).on('click','.submit',function(e){
     e.preventDefault();
     $post = $(this);
    var username2 = $(this).parent().find("#username").val();
    var comment2 = $(this).parent().find("#comment").val();

    $commentsec = $(this).closest("form").next(".comments");

    //Get values of input fields from DOM structure 
    var dataString = {
        id: $(this).parent().find("#id").val(),
        username: $(this).parent().find("#username").val(),
        uid: $(this).parent().find("#uid").val(),
        comment: $(this).parent().find("#comment").val()
    };
   //Get values of input fields from DOM structure 
   var dataString = {
        id: $(this).parent().find("#id").val(),
        username: $(this).parent().find("#username").val(),
        uid: $(this).parent().find("#uid").val(),
         comment: $(this).parent().find("#comment").val()
    };

   $.ajax({
   url:'comments.php',  
   data:dataString,
   success:function(){
 $commentsec.append('<p class="written"><a href="users.php?id= <?php echo $id3; ?>"><b style=color:black !important>'+username2+'</b> </a>'+comment2+"</p>"+'<div class="dropdown"><img src="ellipsis.png" class="dots"><div class="dropdown-content"><br><p  class="delete" data-delete=<?php echo $commentid; ?>">delete</p></div></div>');
     $(" #comment").val("");   
   }
   });
});

我希望每当用户单击此按钮时,都会弹出一个警报,并且该评论应附加到用户现在编写的此表单中,这整个代码在 google chrome 中运行良好,但在 firefox chrome 或 microsoft edge 中无法运行,我不知道该怎么办

标签: javascriptjquerycross-browser

解决方案


推荐阅读