1

誰かがこのコードで私を助けてくれますか? これは修正するのがばかげているかもしれませんが、私は今、何時間もこれにこだわっています! pageinit イベントは発生しません。それを起動させる唯一の方法は、スクリプトを本体内の終了タグの直前に移動することですが、この奇妙な構造は公式ドキュメントで見つけられず、間違っていると思います! Samsung phone emulator (avd) でテストしています。

<!DOCTYPE html>
<html>
  <head>
    <meta name="generator"
    content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1" />


    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script>
       $( document ).delegate("#aboutPage", "pageinit", function () {
                alert('ok');
            alert($('#homePage').text());
        });

</script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    <title>Test Mobile Application</title>
  </head>
  <body>
    <div data-role="popup" id="popupBasic">
      <p>-....</p>
    </div>
    <!-- Begin Homepage -->
    <section id="homePage" data-role="page" data-theme="a">
      <header data-role="header" data-position="fixed">
        <h1>Header</h1>
      </header>
      <div class="content" data-role="content">
        <p>Homepage</p>
        <a onclick="javascript:alert($('#homePage').text());" data-role="button">aaaaa</a>
        <p>
          <a href="#aboutPage">Go to About Page</a>
        </p>
        <a href="#popupBasic" data-rel="popup">Open Popup</a>
      </div>
      <footer data-role="footer" data-position="fixed">
        <h1>Footer</h1>
      </footer>
    </section>
    <!-- End Homepage -->
    <!-- Begin About Page -->
    <section id="aboutPage" data-role="page" data-theme="b">
      <header data-role="header" data-position="fixed">
        <h1>Header</h1>
      </header>
      <div class="content" data-role="content">
        <p>This is About Page</p>
        <p>
          <a href="#portfolioPage">Go to Portfolio Page</a>
        </p>
      </div>
      <footer data-role="footer" data-position="fixed">
        <h1>Footer</h1>
      </footer>
    </section>
    <!-- End About page -->
    <!-- Begin Portfolio Page -->
    <section id="portfolioPage" data-role="page" data-theme="a">
      <header data-role="header" data-position="fixed" data-theme="d">
        <h1>Header</h1>
      </header>
      <div class="content" data-role="content" data-theme="c">
        <p>This is Portfolio Page</p>
        <p>
          <a href="#homePage">Go back to Homepage</a>
        </p>
      </div>
      <footer data-role="footer" data-position="fixed" data-theme="d">
        <h1>Footer</h1>
      </footer>
    </section>
    <!-- End Portfolio page -->
  </body>
</html>
4

2 に答える 2

2

あなたのコードは問題なく動作します。 ボタンをクリックするか、リンクpageinit()を使用して About ページを取得するときに、 が 1 回だけ呼び出されます。aaaaGo to About Page

ただし、いくつかのこと:

最初にリンクjquery.mobileしてから使用する

<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
    //Your code as of right now
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

する必要があります

<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script>
    //Your code goes here
</script>

2番目にjquery 1.8.2を使用しているため、からdelegate()への切り替えを検討できますon()

   $(document).on("pageinit", "#aboutPage", function () {
        alert('ok');
        alert($('#homePage').text());
    });
于 2013-02-07T07:47:55.413 に答える