0

使用 jquery-1.2.7.tools.min.js 中的覆盖工具。我有几个 div 设置为覆盖在“img”和一些“a”标签上。

<img src="/image/test.png" rel="#1485">
<div id="1485" class="simple_overlay">
    <a rel="1486">1</a>
    <a rel="1487">2</a>
    <a rel="1488">3</a>
<div id="1486" class="simple_overlay">
    <a rel="1486">1</a>
    <a rel="1487">2</a>
    <a rel="1488">3</a>
<div id="1487" class="simple_overlay">
    <a rel="1486">1</a>
    <a rel="1487">2</a>
    <a rel="1488">3</a>

当我单击“a”链接之一时,我希望显示与其 id 匹配的覆盖 div,并隐藏其他。但是,在使用这样的 jquery 代码时:

<script>
    $(document).ready(function () {
        $('img[rel]').overlay({
            oneInstance: false
        });

        $('a[rel]').overlay({
            oneInstance: false,
            onLoad: function (event) {
                $('.simple_overlay').not($(this)).hide();
            }
        });
    });
</script>

或使用这个:

$(this).siblings().hide()

“这个”名称不符合我的要求。本质上,所有 .simple_overlay 类的 div 都隐藏在 hide() 调用中。我希望显示带有单击的 rel id 的 div,并隐藏其他的,但似乎我弄错了“this”是什么......谁能告诉我在这种情况下“this”是什么?

4

1 回答 1

0

this is a DOM element when you are inside of a callback function (in the context of jQuery), for example, being called by the click, each, bind, etc. methods.

So .overlay() would need to specify a call back function in order to know what "this" we are talking about.

Try this to debug:

console.log($(this));
$('.simple_overlay').not($(this)).hide(); 

if the console shows that $(this) is undefined you may want to think about modifying your code to use an event bind rather than an anonymous function

You could always bind the selector you want to a click event and hide it that way though

$('.simple_overlay').on('click', function() {
           $(this).hide();
        }
    });
于 2013-06-06T20:35:33.093 回答