0

编辑:这实际上是 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;
}

}
4

1 回答 1

0

我通过使用验证声明符号而不是直接设置验证器设置来解决它,但我不知道为什么。如果有人能解释我将不胜感激(我厌倦了看它:)) errorPlacement 被成功覆盖并在这两种情况下都有效。提交淘汰赛绑定只是没有工作。

而不是像这样覆盖errorPlacement函数

$("form").each(function() {        
        var validator = $(this).data('validator');
        if (typeof validator != 'undefined') {
            validator.settings.errorPlacement = $.proxy(function(error, inputElement) {
                //
                // do stuff with the error object
                //
             }, $(this));
         }
 });

我把它改成了这个,随便尝试一下,它就奏效了:

$("form").each(function () {
    var validator = $(this).data('validator');
    if (typeof validator != 'undefined') {
        $(this).validate({
            errorPlacement: $.proxy(function (error, inputElement) {
                //
                // do stuff with the error object
                //
             }, $(this));
         }
 });
于 2013-10-23T08:35:17.990 回答