jquery 点击页面上的按钮时移动页面退出
jquery mobile page exits when clicking a button on the page
我有几个页面是这样定义的:
<div data-role="page" id="home">
...
</div>
<div data-role="page" id="settings">
...
<button id="testSettingsButton">Test</button>
</div>
javascript 看起来像这样:
$(document).on("touchend", "#testSettingsButton", function(e) {
try {
// connect to remote database
// an error is thrown and caught by the db library code
} catch (err) {
// not reached
}
});
当用户单击 Test
按钮时,jquery 移动设备会显示 home
屏幕,而不是停留在 setting
屏幕上。
为什么会这样?我该如何修复或调试此问题?
我在 Cordova 4.1.2 上使用 Jquery Mobile 1.4.5。
解决方案非常简单 - 我忘记在方法中添加 e.preventDefault();
。添加这个解决了这个问题。
$(document).on("touchend", "#testSettingsButton", function(e) {
e.preventDefault();
try {
// connect to remote database
// an error is thrown and caught by the db library code
} catch (err) {
// not reached
}
});
我有几个页面是这样定义的:
<div data-role="page" id="home">
...
</div>
<div data-role="page" id="settings">
...
<button id="testSettingsButton">Test</button>
</div>
javascript 看起来像这样:
$(document).on("touchend", "#testSettingsButton", function(e) {
try {
// connect to remote database
// an error is thrown and caught by the db library code
} catch (err) {
// not reached
}
});
当用户单击 Test
按钮时,jquery 移动设备会显示 home
屏幕,而不是停留在 setting
屏幕上。
为什么会这样?我该如何修复或调试此问题?
我在 Cordova 4.1.2 上使用 Jquery Mobile 1.4.5。
解决方案非常简单 - 我忘记在方法中添加 e.preventDefault();
。添加这个解决了这个问题。
$(document).on("touchend", "#testSettingsButton", function(e) {
e.preventDefault();
try {
// connect to remote database
// an error is thrown and caught by the db library code
} catch (err) {
// not reached
}
});