ホームページ  >  記事  >  ウェブフロントエンド  >  jQueryモバイルクラスlibrary_jqueryを使用した場合のナビゲーション履歴を読み込む方法の紹介

jQueryモバイルクラスlibrary_jqueryを使用した場合のナビゲーション履歴を読み込む方法の紹介

WBOY
WBOYオリジナル
2016-05-16 15:27:321321ブラウズ
jQuery.mobile.navigate( url [, data ] )

URL を変更し、履歴を追跡します。ブラウザーと履歴のない新しい API で動作します

  • url: は必須パラメータです。タイプ: 文字列
  • data: はオプションのパラメータです。タイプ: オブジェクト。

ハッシュ フラグメントを 2 回変更し、ナビゲーション イベント データを提供するログを作成したときにブラウザーが後方に移動した履歴

// Starting at http://example.com/
// Alter the URL: http://example.com/ => http://example.com/#foo

$.mobile.navigate( "#foo", { info: "info about the #foo hash" });
 
// Alter the URL: http://example.com/#foo => http://example.com/#bar

$.mobile.navigate( "#bar" );
 
// Bind to the navigate event

$( window ).on( "navigate", function( event, data ) {
 console.log( data.state.info );
 console.log( data.state.direction )
 console.log( data.state.url )
 console.log( data.state.hash )
});


 
// Alter the URL: http://example.com/#bar => http://example.com/#foo

window.history.back();
 
// From the `navigate` binding on the window, console output:
// => "info about the #foo hash"
// => "back"
// => "http://example.com/#bar
// => "#bar"

ナビゲーション方法を使用してリンクのクリックをハイジャックし、コンテンツをロードします

// Starting at http://example.com/
// Define a click binding for all anchors in the page

$( "a" ).on( "click", function( event ) {
 
 // Prevent the usual navigation behavior

 event.preventDefault();
 
 // Alter the url according to the anchor's href attribute, and
 // store the data-foo attribute information with the url
 $.mobile.navigate( this.attr( "href" ), { foo: this.attr( "data-foo" ) });
 
 // Hypothetical content alteration based on the url. E.g, make
 // an ajax request for JSON data and render a template into the page.

 alterContent( this.attr( "href" ) );
});

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。