mootools自我参考

时间:2013-03-27 11:34:17

标签: mootools this self

我如何处理mootools中的自我引用? 在我看到下一个容器后,我将删除单击的“删除”按钮。 使用Jquery,我可以通过“this”运算符来完成它。

 window.addEvent('domready', function(){

        $$('div.showButton').addEvent('click', function(){

        // show next Container 
        $$('div.container').getNext().show('inline');   

        // remove this "showButton"
        $(this).remove() // not working

        });
        });





   <!-- container 1 -->
    <div class="container">

        <div class="showButton">Show next container</div>
        <div class="hideButton">hide this container</div>

    </div>

    <!-- container 2 -->
    <div class="container" style="display:none">

        <div class="showButton">Show next container</div>
        <div class="hideButton">hide this container</div>

    </div>

1 个答案:

答案 0 :(得分:0)

你必须记住mootools不是jquery,它们在实现方面有所不同。

首先$$函数返回元素数组,而不是元素,所以你不能在数组上调用show - 你必须得到你想要的元素(通常是第一个)。

第二 - 您可以使用$(this)调用当前元素,但它有点不必要,因为您已经在元素事件中,所以您可以使用“this”:

http://jsfiddle.net/kk4gz/2/

    $$('div.showButton').addEvent('click', function(){

       // show next Container 
       $$('div.container')[0].getNext().show('inline');   

       // remove this "showButton"
       this.remove();

    });