0

私はjqueryモバイルシングルページアプリケーションに取り組んでいるので、すべてのページが異なるIDのindex.phpにあります.私の問題は、すべてのページに単一のヘッダーを作成しようとしたときに、そのヘッダーファイルをすべてのページに追加することです.ヘッダーが機能していません。index.html の最初のページでそのヘッダーを使用しましたが、正常に動作していますが、外部から呼び出すと正しく動作しません。

appheader.html としてのヘッダー ファイル namd は次のとおりです。

<div data-role="header" data-theme="p" data-position="fixed">
        <h1></h1>
        <a href="#left-panel" data-icon="bars" data-iconpos="notext" data-role="button">Menu</a>
    </div>

<a data-theme="d" data-corners="false" data-role="button" href="#"> <img src="images/pearl-logo.png" alt="rss" style="display: block; margin: 1.5em auto;"></a>

<div data-role="panel" id="left-panel"  data-position="left" data-display="push" data-dismissible="true" data-theme="c">
<ul data-role="listview" data-theme="d" data-divider-theme="d" data-icon="false" data-global-nav="docs" class="jqm-list">
            <li data-role="list-divider">LINKS</li>
            <li><a href="#home">Home</a></li>
            <li><a href="#20years">20 Years</a></li>
            <li><a href="#courses">Courses</a></li>
            <li><a href="#events">Fun @ Pearl</a></li>
            <li><a href="#gallery">Gallery</a></li>
            <li><a href="#noida">Noida</a></li>
            <li><a href="#jaipur">Jaipur</a></li>
            <li><a href="#delhi">Delhi</a></li>
            <li><img src="images/pearl-logo.png"></li>
</ul>       
</div>

これは、id と組み合わせた異なるページを持つ index.html にこのページを追加するための jquery です。

<script>
$(document).ready(function(e) {

        $('[data-role=page]').one('pagebeforeshow', function (event, ui) {
       $("#" + event.target.id).find("[data-role=appheader]").load("appheader.html", function(){
         //$("#" + event.target.id).find("[data-role=panel]").trigger("pagecreate");
         // refresh the page again
        //   alert('ok');
         $("#" + event.target.id).trigger("create"); 
           });
        }); 

});

</script>

index.html内のすべてのページでそれを呼び出す方法は次のとおりです。

<div data-role="page" id="20years" data-title="20years" data-url="20years"> 
<div data-role="appheader"></div>
  <div data-role="content">
</div>
</div>

スライダーは index.html で使用すると正常に動作しますが、別のファイルとして呼び出すと動作しません。

別の質問は、すべてのページが異なる ID を持つため、このヘッダー パネルをスワイプさせるにはどうすればよいかということです。

<script type="text/javascript">
$( document ).on( "pageinit", "#home", function() {
    $( document ).on( "swipeleft swiperight", "#home", function( e ) {
        // We check if there is no open panel on the page because otherwise
        // a swipe to close the left panel would also open the right panel (and v.v.).
        // We do this by checking the data that the framework stores on the page element (panel: open).
        if ( $.mobile.activePage.jqmData( "panel" ) !== "open" ) {
            if ( e.type === "swipeleft"  ) {
                $( "#right-panel" ).panel( "open" );
            } else if ( e.type === "swiperight" ) {
                $( "#left-panel" ).panel( "open" );
            }
        }
    });
});

</script>

このjqueryで別のページを呼び出すにはどうすればよいですか。

4

1 に答える 1

2

交換してみる

$("#" + event.target.id).trigger("create");

$("#" + event.target.id).trigger("pagecreate");

于 2013-09-20T06:23:31.160 に答える