javascript Jquery 手风琴更改事件不会触发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15297481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 00:15:48  来源:igfitidea点击:

Jquery accordion change event doesn't fire

javascriptjqueryeventsaccordion

提问by Sean

This doesn't work:

这不起作用:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui-1.10.1.custom.css" />
    <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.10.1.custom.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {

            $("#accordion").accordion({
                change: function (event, ui) { alert('test'); }
            });

        });
    </script>

</head>
<body>


    <div id="accordion">
        <h2><a href="#">Header1</a></h2>
        <div>
            <p>content 1</p>
        </div>
        <h2><a href="#">Header2</a></h2>
        <div>
            <p>content 2</p>
        </div>
    </div>


</body>
</html>

采纳答案by PSR

Did you make sure and include the proper reference to the jQuery library?

您是否确保并包含对jQuery库的正确引用 ?

try with this

试试这个

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.js'></script>

回答by Frédéric Hamidi

The accordion widget does not expose a changeevent in recent versions of jQuery UI.

手风琴小部件不会change在最新版本的 jQuery UI 中公开事件。

You can bind to the activateevent instead:

您可以改为绑定到activate事件:

$("#accordion").accordion({
    activate: function(event, ui) {
        alert(ui.newHeader.text());  // For instance.
    }
});