jQueryMobile新版中導航欄按鈕消失的解決方法

最近將jQueryMobile的庫更新到最新版後,發現以前用 jQueryMobile 寫的一些東西, header 導航欄上的“後退”按鈕統統不見了。這個功能挺貼心的,可以自動爲你的 Web App 在不同頁面之間跳轉的時候增加導航功能。於是翻 jQueryMobile 的官方文檔,在不起眼的地方發現了這樣一句話:

jQuery Mobile has a feature to automatically create and append "back" buttons to any header, though it is disabled by default. This is primarily useful in chromeless installed applications, such as those running in a native app web view. The framework automatically generates a "back" button on a header when the page plugin’s addBackBtn option is true. This can also be set via markup if the page div has a data-add-back-btn="true" attribute.

原來默認把這個功能是關閉。打開它很簡單,需要在頁面源代碼的 page 中加上 data-add-back-btn="true" 。

同時頁面的代碼中加上一句 js 代碼即可:

  1. $(document).bind("mobileinit"function() {  
  2. $.mobile.page.prototype.options.addBackBtn = true;  
  3. }); 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章