Jquery Mobile-使用$.Mobile.navigate后事件不会绑定
Jquery Mobile - events wont bind after using $.mobile.navigate
当我使用$.mobile.navigate更改页面时,页面会加载,但我的自定义脚本不会绑定到元素。如果刷新页面,自定义脚本将加载并绑定到元素。我有一个选择元素可以在页面之间选择:
<select name="calc-Nav" id="calc-Nav">
<option value="a.php">A</option>
<option value="b.php">B</option>
<option value="c.php">C</option>
</select>
这是绑定到select元素的事件:
$("#calc-Nav").on("change", function (e) {
var opt = $("#calc-Nav option:selected").val();
if (opt) {
e.preventDefault();
$.mobile.navigate(opt);
}
});
此外,我按照以下顺序链接到我的javascript文件:
<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>
有人知道怎么做吗?
谢谢。
编辑:这是用于所有页面的模板这是每个页面的标准模板。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
</head>
<body>
<div data-role="page">
<div data-role="header">
<div class="ui-field-contain">
<select name="calc-Nav" id="calc-Nav">
<option value="Index.php">Home</option>
<option value="a.php">a</option>
<option value="b.php">b</option>
<option value="c.php">c</option>
</select>
</div>
</div>
<div data-role="main" class="ui-content">
<div id="index">
<h1> Form goes Here. </h1>
</div>
</div>
<div data-role="footer">
<h1>Footer</h1>
</div>
</div>
</body>
<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="js/formulas.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
</html>
您需要将它们绑定到文档
尝试-
$(document).on("change","#calc-Nav", function (e) {
var opt = $("#calc-Nav option:selected").val();
if (opt) {
e.preventDefault();
$.mobile.navigate(opt);
}
});
还要确保在jqmobile脚本
相关文章:
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- 如何在tinymce编辑器中将点击事件绑定到html标签
- 如何将事件绑定到从AJAX请求注入的HTML
- 将click事件绑定到AngularJS指令中的子元素
- Jquery将事件绑定到页面上的多个实例
- 事件绑定到动态创建的元素
- 使用jQuery进行事件绑定
- 如何将单击事件绑定到其他类
- 更改事件绑定's函数在页面加载时调用
- Jquery事件绑定获胜'当作为方法调用时不起作用,但当直接在控制台中调用时会起作用
- 动态创建的DOM元素上的jQuery事件绑定
- 我是否可以使用 Angular 将鼠标向上事件绑定到文档正文
- 将事件绑定到除 data-rel= BACK 之外的所有锚标记
- 将函数事件绑定到更改函数的复选框/标签
- 使用 Angular 和 UI-bootstrap 对模态事件绑定无法工作的指令
- 聚合物 - 将事件绑定到动态创建的元素
- 将事件绑定到其他UI组件's函数,在Kendo MVVM中
- jQuery Mobile——事件绑定
- JQuery无法将模糊事件绑定到所有<输入>页面中的元素
- 将点击事件绑定到新元素&使得ID'是独一无二的