lor*_*afs 3 jquery jquery-selectors shorthand
我有一个非常简单的问题,而不是做这样的事情:
$(".one").click(function() {
$(this).find('.two').find('.three').css...
});
Run Code Online (Sandbox Code Playgroud)
使用此HTML:
<div class="one">
<div class="two">
<div class="three"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
有一个简短的手,你可以在某种程度上跳过单词find?
Sus*_* -- 13
$('#one #two #three')
Run Code Online (Sandbox Code Playgroud)
但请记住,ID在页面中应该是唯一的
所以$('#three').css()应该足够了
当元素是class元素或元素时,它是有意义的tagNames
$('.one .two .three') <--
$('div span p') <-- These are fine
Run Code Online (Sandbox Code Playgroud)
所有这些应该工作
// Using find to target the class
$(this).find('.two').find('.three').css('border', '1px dashed red');
// Using find to target the class
$(this).find('.two .three').css('border', '1px dashed red');
// Using the this context
$('.two .three',this).css('border', '1px dashed red');
// Using the this context and immediate children
$('> .two > .three',this).css('border', '1px dashed red');
Run Code Online (Sandbox Code Playgroud)
>只会让直系孩子.其他2个this用作上下文
| 归档时间: |
|
| 查看次数: |
2000 次 |
| 最近记录: |