hoe*_*erf 4 jquery this selector
是否可以:selector在jQuery中使用以下内容?
$('.galler_attr').bind('click', function() {
$(this:first-child).css('color', 'red');
});
Run Code Online (Sandbox Code Playgroud)
Rus*_*Cam 16
不.您正在尝试将函数上下文与字符串混合使用.
使用this的情况下选择的,或致电find()上$(this)的元素的DOM范围内进行搜索.或
$('.galler_attr').bind('click', function() {
$(this).find(':first-child').css('color', 'red');
});
Run Code Online (Sandbox Code Playgroud)
或者这个(内部解决了上述内容):
$('.galler_attr').bind('click', function() {
$(':first-child', this).css('color', 'red');
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25369 次 |
| 最近记录: |