我想选择p
.section容器中的所有元素,但只是在包含已单击的a.open链接的元素中
$('.section').delegate('a.open', "click", function(){
$(this).parent().filter('p').show(); //I want to select all `p` elements in .section container, but just in th one that containts the a.open link that has been clicked
})
Run Code Online (Sandbox Code Playgroud)
谢谢
您可以将delegateTarget作为上下文传递(delegateTarget是事件对象的一个属性,它传递给处理函数,并且是"处理"委托的DOM元素
$('.section').delegate('a.open', "click", function(e){
$('p', e.delegateTarget).show()
//This means show all <p> elements in the context defined by e.delegateTarget
})
Run Code Online (Sandbox Code Playgroud)
看看这个小提琴http://jsfiddle.net/jWYKv/