jQuery隐藏在AJAX调用后不起作用

jQuery隐藏在AJAX调用后不起作用,jquery,Jquery,我使用jQueryhide()函数在两种情况下隐藏元素。一个是正常情况,它正在那里工作。另一种情况是,包含元素的部分通过AJAX加载。我已经在加载内容的页面中编写了脚本。但在这种情况下,该函数不起作用。我已经在onclick中给出了函数。单击会被触发,但不会隐藏图元。由于点击被触发,我认为没有必要使用live() 我的元素代码如下: <input type="button" onclick="addMoreElements(this.id);" value="Add" id="406" c

我使用jQuery
hide()
函数在两种情况下隐藏元素。一个是正常情况,它正在那里工作。另一种情况是,包含元素的部分通过AJAX加载。我已经在加载内容的页面中编写了脚本。但在这种情况下,该函数不起作用。我已经在
onclick
中给出了函数。单击会被触发,但不会隐藏图元。由于点击被触发,我认为没有必要使用
live()

我的元素代码如下:

<input type="button" onclick="addMoreElements(this.id);" value="Add" id="406" class="button">
试试这个:

HTML


我尝试了你的代码,请尝试在html元素之前定义你的javascript。应该这样做

示例代码:

 <script type="text/javascript">

    function addMoreElements(){
          $("#406").hide();     
    }
</script>

<input type="button" onclick="addMoreElements();" value="Add" id="406" class="button" />

}))

如果您观察到您正在将this.id传递给javascript函数并显式使用$(“#406”)。你可以试试这个

function addMoreElements(currentelement){
    $("#"+currentelement).hide();
}
希望这有帮助。

控制台(或开发人员工具)中有错误吗?
$('#406').on('click', function() {
    $(this).hide();
})​
 <script type="text/javascript">

    function addMoreElements(){
          $("#406").hide();     
    }
</script>

<input type="button" onclick="addMoreElements();" value="Add" id="406" class="button" />
$(document).ready(function(){
   $(".element").click(function(){
      //do something with the element by using $(this)
    });
function addMoreElements(currentelement){
    $("#"+currentelement).hide();
}