0

好的,所以这个非常简单,将实时点击与点击影响 maccordion 在两者中遵循相同行为的能力。正在讨论的行是“ $(".maccordion h3 input").live('click', function () { "。

我想要的只是您单击按钮的基本操作 maccordion 不执行任何操作单击标题中的其他任何位置,它遵循正常动画。

编辑:只是为了添加我已经尝试添加 e.stopImmediatePropagation(); 和 e.stopPropagation(); 尼特什么都做。我还必须使用 live,因为插入的代码是动态创建的,并通过 ajax 引入。

<div class="maccordion">
<h3><input type='button' value='cick'></h3>
<ul>
    <li><a href="/custom.html">Custom</a>
</ul>
<h3><a href="/account">Account</a></h3>
<ul>
    <li><a href="/account/avatar.html">Avatar</a>
</ul>

$(function () {

    //Turn the div into an accordion
    $(".maccordion").maccordion({
        header: 'h3'
    });

    //capture the click on the a tag
    $(".maccordion h3 input").live('click', function () {
        return false;
    });
});

4

1 回答 1

0

演示

.live()更改为.on()

$(function () {

    //Turn the div into an accordion
    $(".maccordion").accordion({
        header: 'h3'
    });

    //capture the click on the a tag
    $(".maccordion h3 input").on('click', function () {
        return false;
    });
});

从 jQuery 1.7 开始,该.live()方法已被弃用。用于.on()附加事件处理程序。旧版本的用户jQuery应该.delegate()优先使用.live().

此方法提供了一种将委托事件处理程序附加到页面的文档元素的方法,这在将内容动态添加到页面时简化了事件处理程序的使用。有关更多信息,请参阅方法中对直接事件与委托事件的讨论.on()

.live()根据其后继者重写该方法很简单;这些是对所有三种事件附件方法进行等效调用的模板:

$(selector).live(events, data, handler);                // jQuery 1.3+
$(document).delegate(selector, events, data, handler);  // jQuery 1.4.3+
$(document).on(events, selector, data, handler);        // jQuery 1.7+
于 2013-08-26T16:29:47.947 回答