我的页面包含以下链接
<a id="21561" class="delete_item" href="#" name="baseMenu">
<img class="icons" src="../images/delete.gif">
</a>
<a id="219350" class="delete_item" href="#" name="menuOptions">
<img class="icons" src="images/delete.gif">
</a>
这两个链接之间的唯一区别是 name 属性。
我遇到的问题是,这些链接是通过 $.post()
方法动态注入(inject)到 HTML 文档中的
我试图在单击删除链接时获取 name 属性,但是当我使用 $(this)
属性结合使用它时,它似乎不起作用。
谁能帮我在点击事件中获取 .delete_item 链接的 $(this)
属性。
任何帮助将不胜感激。提前致谢
$(document).on("click", $(".delete_item") , function(){
var test = $(".delete_item", this);
console.log(test);
return false; //We just want get the value for now
no need to parse the rest of the code. We now it works
//rest of the ajax code .......
)
最佳答案
您不需要在委托(delegate)事件定义中使用 jQuery 函数调用,我认为这是问题的根源。一旦你解决了这个问题,你就应该能够使用 $(this)
。
一个例子:
$(document).on("click", ".delete_item" , function(){
var test = $(this);
console.log(test);
return false; //We just want get the value for now no need to parse the rest of the code. We now it works
//rest of the ajax code .......
});
关于jquery - 如何在委托(delegate)事件中获取 $(this),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26170728/