0

我有以下代码,我正在尝试调用Floater.Create()click对象[data-floatertype=minimize]。我不想使用 ID,只是通过 DOM 工作。仅供参考,该[data-floatertype=minimize]对象已经.on('click',...)附加了一个,我希望它两者都做。

<div data-floater="true" data-minimized="false">
    <p data-floatertype="title" class="title" style="font-size: 20px;">Welcome</p>
    <a data-floatertype="minimize" href="#" class="minimize" style="right: 30px;">-</a>  
    <a href="#" data-floatertype="close" class="close">X</a>
    <div data-floatertype="content" class="content" style="display: block;">                
    <div style="display: block; text-align: center;" data-display="block">
        <h3>Floaters 101</h3>
        <hr>
        <p style="text-align:left;">You can have as many floaters open as you would like.</p>
        <p style="text-align:left;">Floaters can be minimized by using the minimize button in the top right.</p>
        <p style="text-align:left;">Floaters can also be closed using the close button in the top right.</p>
        <hr>
        <p>Try minimizing this window now.</p>
        <script type="text/javascript">
            $(this).parent().siblings('[data-floatertype=minimize]').on('click', function () {
                Floater.Create("Good job!", "floatertutorial.php", {intro: "3"});
            });
        </script>
    </div>              
</div>

我怀疑的问题是$(this).parent().siblings(...)没有返回正确的对象,或者根本没有返回。或者.......on('click',...)没有正确绑定。在任何情况下,Floater.Create()单击链接时都不会调用该方法。帮助?

4

1 回答 1

1

this不受 HTML 元素的“范围”影响,this指的是window您使用它的位置。你需要这样做:

$('[data-floatertype=minimize]').on('click', function () {
    Floater.Create("Good job!", "floatertutorial.php", {intro: "3"});
});
于 2013-03-29T15:48:42.510 回答