JQM pagebeforechange和事件源

时间:2012-02-07 15:37:54

标签: javascript jquery jquery-mobile

收听pagebeforechange事件......

$(document).bind(“pagebeforechange”,function(event,data){

//事件是从锚标签触发的...... //这里是否可以引用锚(或event.srcElement)

});

要么 .....

以下是一个简单的示例,如果有人想尝试一下......

    <head>
      <title>Main menu</title>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css"
      />
      <script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
      <script type="text/javascript">
          $(document).bind("pagebeforechange", function (event, data) {
              if (typeof data.toPage === "string") {
                  //event is triggered from an anchor tag...
                  //Is it possible to get reference to anchor( or event.srcElement)  here
                  event.preventDefault();
              }
          });
      </script>
      <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
    </head>
    <body>
      <div data-role="page" id="home">
        <div data-role="header" data-theme="a"></div>
        <div data-role="content">
          <ul data-role="listview" data-inset="true">
            <li>
              <a href="#category-items?category=animals">Animals</a>
            </li> 
          </ul>
        </div>
      </div>
    </body>

    </html>

1 个答案:

答案 0 :(得分:0)

怎么样     event.liveFired.activeElement;