私はjquery mobileで戻る/進むボタンを自分で処理しています。問題は、ユーザーが戻るボタンをクリックすると、jquery が ajax リクエストを送信してページを再初期化し、すべての作業が台無しになることです。私は設定data-backbtn="false"
し $.mobile.ajaxEnabled = false;
ましたが、これらのトリックはどれもうまくいきません。何か案が?
3 に答える
2
あなたの問題は$.mobile.ajaxEnabled = false;にもあると思います。取り扱い。
そのコード サンプルは、次のように mobileinti イベントからトリガーする必要があります。
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
もう 1 つ、次のように、jQuery Mobile を初期化する前に mobileinit イベントをトリガーする必要があります。
<script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>
<script>
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
例:
HTML 1 :
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>
<script>
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" id="index">
<div data-theme="a" data-role="header">
<h3>
First Page
</h3>
<a href="second.html" class="ui-btn-right">Next</a>
</div>
<div data-role="content">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
HTML2:
<!DOCTYPE html>
<html>
<head>
<title>jQM Complex Demo</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no; target-densityDpi=device-dpi"/>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://www.dragan-gaic.info/js/jquery-1.8.2.min.js"></script>
<script>
$(document).bind("mobileinit", function () {
$.mobile.ajaxEnabled = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
<div data-role="page" id="second">
<div data-theme="a" data-role="header">
<h3>
Second Page
</h3>
<a href="index.html" class="ui-btn-left">Back</a>
</div>
<div data-role="content">
</div>
<div data-theme="a" data-role="footer" data-position="fixed">
</div>
</div>
</body>
</html>
于 2013-03-14T13:50:18.277 に答える
0
私は私のために働いたこのラインを使用することになりました、
$(window).off('popstate');
于 2013-03-17T09:36:58.740 に答える
0
jQuery Mobile は、擬似ページが移動された後に DOM から削除します (これは外部ページのみです)。data-role="page"
疑似ページの要素にdata-dom-cache="true" 属性を追加することで、単一の疑似ページでこの動作を停止できます。
<div data-dom-cache="true" data-role="page">
...
</div>
この機能を有効にする (実際には無効にする) 方法は他にもあります。ここでそれらについて読むことができます
于 2013-03-14T13:52:58.277 に答える