【发布时间】:2014-02-28 06:44:25
【问题描述】:
我有一个要在 JQuery Mobile 混合应用程序中使用的自定义函数。提交表单时,我希望触发我的函数,而不是默认处理程序。
我有以下表格:
<form id="frmFillup">
<label for="odReading">Total Odometer Reading:</label>
<input type="number" data-clear-btn="true"
name="odReading" id="odReading" value="1">
<label for="fuelReading">Total Fuel:</label>
<input type="number" data-clear-btn="true"
name="fuelReading" id="fuelReading" value="1">
<label for="totalPrice">Total Price:</label>
<input type="number" data-clear-btn="true"
name="totalPrice" id="totalPrice" value="1">
<label for="stationAddress">Station address:</label>
<textarea
name="stationAddress" id="stationAddress">1 main st</textarea>
<button data-theme="a" name="saveFillup" id="saveFillup">Save Fillup</button>
</form>
我在 HTML 页面的顶部安装了一个监听器:
$('#frmFillup').submit(
function (e) {
e.preventDefault();
e.stopImmediatePropagation();
alert('Saving!!');
saveFillup();
}
);
但是,默认提交函数似乎仍在触发,而我的自定义函数从未被触发(我的自定义事件侦听器中也没有收到警报框)。 Chrome 开发工具不会在控制台中显示任何 javascript 错误——看起来它只是没有绑定提交处理程序。非常感谢任何和所有的帮助!
完整代码在 github 上https://github.com/cristoslc/petrolog/blob/master/www/index.html
【问题讨论】:
标签: javascript jquery jquery-mobile