2013-03-08 42 views
2

这不起作用:jQuery的手风琴变化不会触发事件

<!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> 

回答

0

你确定,包括适当的参考jQuery库?

尝试用这种

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

感谢。我只是从JQuery Themeroller网站下载了这个JQuery文件,所以我没有想到它会成为问题! – Sean 2013-03-08 15:34:00

+2

看起来这是1.10的问题 - 感谢您的帮助。 – Sean 2013-03-08 15:39:46

15

折叠菜单在最近版本的jQuery用户界面的不公开change事件。

您可以绑定到activate事件,而不是:

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

这真的应该是被接受的答案。我敢打赌,大多数人都遇到了jQuery UI升级问题。 – CarComp 2014-05-13 14:27:37