-1

我有以下代码:

$('.my-image').function(){
   $(this + ' div').show();
},
function(){
   $(this + ' div').hide();
});

我知道它不起作用,因为我请求一个带有 div 的对象,但我不知道我应该如何更明确。

<div id='galery'>
   <div class='my-image'><div></div></div>
   <div class='my-image'><div></div></div>
</div>

我应该如何调用 jquery 函数来显示内部 div(子 div)?

4

3 回答 3

4

this是一个 DOM 元素;您不能将其连接到选择器中。

你正在尝试写

$(this).find('div')
于 2012-09-28T15:50:39.987 回答
3
$(this + ' div').show();

应该

$(this).find("div").show();

或者

$("div", this).show()

this是一个对象,而不是一个字符串。

于 2012-09-28T15:51:09.750 回答
0

带孩子试试:

$('.my-image').function(){
   $(this).children('div').show();
},
function(){
   $(this).children('div').hide();
});
于 2012-09-28T15:52:52.570 回答