3

JQuery-Mobile の折りたたみ可能な展開/折りたたみイベントを使用するために結び付けている次のデモ HTML ファイルがあり、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>

折りたたみと展開は機能しますが、アラートは発生しません。

ありがとう!ノミ

4

1 に答える 1

2

イベントをバインドする前にページが読み込まれるようにPageInit呼び出しを追加します。

例:

コード:

$('#home').live('pageinit', function(event) {
    $('#my-collaspible').bind('expand', function() {
        alert('Expanded');
    }).bind('collapse', function() {
        alert('Collapsed');
    });
});
于 2012-05-30T17:14:47.980 に答える