Javascript Ajax元素看不到JQuery

Javascript Ajax元素看不到JQuery,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,在我的php页面中,当使用jQueryAjax按下按钮时,我会添加新按钮和信息,但是当我单击Ajax附带的新按钮时,它的JQuery不起作用,而旧按钮的JQuery起作用,我的意思是,新按钮看不到我的php页面的javascript文件 我的jqueryajax代码 $("button[name='addnewelement']").click(function() { $.ajax({ type: "POST", url: "addelement.php",

在我的php页面中,当使用jQueryAjax按下按钮时,我会添加新按钮和信息,但是当我单击Ajax附带的新按钮时,它的JQuery不起作用,而旧按钮的JQuery起作用,我的意思是,新按钮看不到我的php页面的javascript文件

我的jqueryajax代码

$("button[name='addnewelement']").click(function() {




$.ajax({    


    type: "POST",
    url: "addelement.php",

    cache: false,
    success: function(html){


    $("#new").append(html);// add new element into index.php
  });
  });
addelement.php

  echo "
      .......
     <button id="<?php echo $row['id']; ?>" name="addnewelement"  >Add</button>
     ....... 
   " ;
我怎样才能解决这个问题

谢谢。

您在addelement.php页面中的回音如下

echo '<button id="'.$row['id'].'" name="addnewelement"  >Add</button>';
exit;
而且最好将退出放在回显之后。确保遵循语法并使用良好的IDE查找语法错误。

您应该使用单击事件处理程序,而不是单击事件处理程序。 以下是链接: 例如


重要的是使用授权,就像你在回答中所做的那样。on With delegation与using相同。单击并不会对动态添加的元素起作用。它不会添加新元素,但在单击按钮时会进入,为什么ajax不起作用?add返回false;在关闭单击功能之前,我之前已经添加了它,问题是,使用ajax创建的元素无法再次运行ajax。我缺少什么?请尝试在类而不是名称上添加单击事件。在HTML中,名称被认为是一个独特的值。我认为这是造成问题的原因。
$( document).on( "click", "button[name='addnewelement']", function() {
$.ajax({    
    type: "POST",
    url: "addelement.php",
    cache: false,
    success: function(html){
    $("#new").append(html);// add new element into index.php
  });
});