【问题标题】:Best way to select a descendant element选择后代元素的最佳方法
【发布时间】:2014-03-06 21:14:22
【问题描述】:

两者有什么区别:

var a = $('.a');
$('.b', a).click(function(){

});

和:

a.find('.b').click(function(){

});

?

【问题讨论】:

标签: javascript jquery jquery-selectors find


【解决方案1】:

第一个 jQuery( selector [, context ] ) 采用 context 被 jQuery 转换为第二个调用 find 。我更喜欢第二个。

在内部,选择器上下文是用 .find() 方法实现的, 所以 $( "span", this ) 等价于 $( this ).find( "span" ), jQuery Docs

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-03-11
  • 1970-01-01
  • 2016-12-04
  • 2010-10-27
  • 2011-09-27
  • 1970-01-01
  • 2011-01-10
  • 2021-10-10
相关资源
最近更新 更多