编辑:这实际上是 Knockout,JQuery 1.10.2 并试图覆盖 jquery.unobtrusivevalidation ErrorPlacement 函数......停止表单元素上的提交绑定工作。
如果我使用 JQuery 1.8.2 运行相同的代码,那么只需将我的 JQuery 文件更改为 1.10.2,我的提交函数就会停止触发......有没有人看到过类似的情况?
我将尽可能多地发布相关代码,以防出现意外情况,但重点是 submitForm 与 jquery 1.8.2 完美绑定到表单提交事件,并且没有任何其他更改 jquery 1.10.2 没有touch submitForm(使用断点和 alert() 语句进行测试)。所有其他淘汰赛绑定似乎仍然有效。
请帮忙。谢谢。
<html>
<head>
<script src="/Content/Scripts/jquery-1.10.2.js"></script>
<script src="/Content/Scripts/jquery-ui/jquery-ui.js"></script>
<script src="/Content/Scripts/jquery-ui-timepicker-addon.js"></script>
<script src="/Content/Scripts/knockout-2.3.0.js"></script>
<script src="/Content/Scripts/knockout-helpers.js"></script>
<script src="/Content/Scripts/knockout.mapping-latest.js"></script>
<script src="/Content/Scripts/underscore.js"></script>
<script src="/Content/Scripts/date.js"></script>
<script src="/Content/Scripts/global.js"></script>
<script src="/Content/Scripts/jquery.blockUI.js"></script>
<script src="/Content/Scripts/jquery.dirtyform.js"></script>
<script src="/Content/Scripts/bootstrap/bootstrap.js"></script>
<script src="/Content/Scripts/sessionTimer.js"></script>
<script src="/Content/Scripts/jquery.livequery.js"></script>
<script src="/Content/Scripts/Ecdm/myCode.js"></script>
</head>
<form action="/Apply" data-bind="submit: submitForm" id="myApplicationForm" method="post">
<!-- html form stuff -->
</form>
<script>
var view;
$(function() {
view = new ModelView({
formSelector: '#myForm',
});
// Base JS model
var model =
{
someProperty: '@Model.SomeProperty',
};
view.bind(model);
});
</script>
</html>
我的代码.js:
function ModelView(params) {
var self = this;
// Default parameters
var args = $.extend({
formSelector: 'form' }, params);
this.bind = function (model) {
// Apply KO bindings
ko.applyBindings(self);
};
this.submitForm = function () {
var form = $(args.formSelector);
form.validate();
if (form.valid()) {
var referenceNumber = $('#ReferenceNumber');
if (a==b) {
showConfirmation();
return false;
}
g_showWait("Please wait...");
return true;
}
return false;
}
}