jquery-mobile - 无法获取要执行的 JQuery-Mobile 可折叠展开/折叠事件

标签 jquery-mobile

我有以下演示 HTML 文件,我想使用 JQuery-Mobile 可折叠展开/折叠事件,但我无法触发 JavaScript 事件。我在这里基于 JSFiddle 示例:http://jsfiddle.net/6txWy/

我觉得我只是忽略了一些简单的东西,但这是我的 HTML 文件:

<html> 
<head> 
  <title>References</title>

  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
  <link rel="stylesheet" href="css/main.css" />

  <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
  <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>  

  <script type="text/javascript">
  $('#my-collaspible').bind('expand', function()
  {
    alert('Expanded');
  }).bind('collapse', function () {
    alert('Collapsed');
  });
  </script>
</head> 

<body>
  <div data-role="page">
      <div data-role="content">
          <div data-role="collapsible" id="my-collaspible">
              <h3>My Title</h3>
              <p>My Body</p>
          </div>
      </div>
  </div>
</body>
</html>

折叠和展开有效,但永远不会触发警报。

谢谢! 跳蚤

最佳答案

添加 PageInit在绑定(bind)事件之前调用以确保页面已加载

例子:

代码:

$('#home').live('pageinit', function(event) {
    $('#my-collaspible').bind('expand', function() {
        alert('Expanded');
    }).bind('collapse', function() {
        alert('Collapsed');
    });
});

关于jquery-mobile - 无法获取要执行的 JQuery-Mobile 可折叠展开/折叠事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10819817/

相关文章:

jQuery 和 jQueryMobile 还是其中之一?

css - 为什么 Chrome 开发者工具和实际的 Chrome 渲染不同?

当我使用 .show() 和 .hide() 时,jQuery 移动按钮会变形

javascript - jquery hide 只隐藏一个按钮

Jquery Mobile - 如何使用 Jquery 小部件工厂在 mobileinit 上运行插件

javascript - 如何降低 jQuery Mobile 中面板的高度

javascript - 如何检测移动设备的移动?

jquery mobile - 更改翻转开关默认状态

jquery - 移动设备和平板电脑上粘性标题上的奇怪 flickr

css - 非插图显示可折叠设置太宽