我有个问题,我不知道怎么解决.我有以下代码:
<div id="one">
<div id="two">
<div id="three">
<img class="close" id="close" src="../img/close.png" height="15px" onclick="close(this)"/>
</div>
</div>
</div>
<script>
$('.close').click(function(){
$(this).parents('#one').css('display','none');
</script>有了这个,如果我点击图像,这将隐藏div "one“(因为我说了名称)。但是..。我能用些瓦尔吗?我是说..。我不想在我的javascript代码上说我想要这样做的ID:$(This).parents().parents()parents().但我知道这是行不通的,xD,我是为这个请求你的帮助的
非常感谢。
发布于 2014-08-23 22:56:37
是的,您可以只使用.parent()而不是.parents(),如下所示:
$('.close').click(function() {
$(this).parent().parent().parent().css('display','none');
});jQuery文档:http://api.jquery.com/parent/
发布于 2014-08-23 22:54:11
根据您的情况,可能最容易将类(例如.select-this-one)添加到您想要在单击图像时选择的div中,然后执行以下操作:
$('.close').on('click', function() {
$(this).parents('.select-this-one').css('display', 'none');
});发布于 2014-08-23 22:59:12
而不是父母使用父母:
$('.close').on('click', function(){
$(this).parent().parent().parent().css('display','none');
});但你还是得数一数你想要上升多少层
https://stackoverflow.com/questions/25467033
复制相似问题