Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建自己的jquery插件-函数问题_Jquery_Function_Plugins - Fatal编程技术网

创建自己的jquery插件-函数问题

创建自己的jquery插件-函数问题,jquery,function,plugins,Jquery,Function,Plugins,我试图通过我自己构建的jquery插件传递一个函数作为选项 在使用以下选项初始化我的插件时: $.fitAjaxSubmit({ formId: "new_team", postUrl: "/teams/create.json", redirectUrl: "/teams/", saveBoxText: "Saving Team...", beforeSubmitFn: function(){ alert('Boo!'); } });

我试图通过我自己构建的jquery插件传递一个函数作为选项

在使用以下选项初始化我的插件时:

$.fitAjaxSubmit({
  formId:         "new_team",
  postUrl:        "/teams/create.json",
  redirectUrl:    "/teams/",
  saveBoxText:    "Saving Team...",
  beforeSubmitFn: function(){ alert('Boo!'); }
});
在我的插件中,我尝试调用beforeimitfn这样的
(我也在使用ajax表单插件):

出于某种原因,beforeSubmitFn在Firefox中可以工作,但在Internet Explorer、Safari和Chrome中根本不起作用

这里有我遗漏的东西吗


提前谢谢

在这里猜测,因为您没有显示所有代码。你在这里发布的代码看起来不错


IE和大多数其他浏览器处理对象映射格式的方式略有不同。您可以在选项定义中检查是否有额外的逗号

在您访问它时,选项可能已超出范围。其他选项值是否有效?你能给我们多一点代码吗?只是增加了更多的代码!谢谢大家!它似乎被隔离到此行$('#'+options.saveBtnId.attr('disabled','disabled').val(options.saveBtnDisableText);-我不知道为什么!似乎不是引起问题的逗号,即也不会抛出JS错误
(function($){
    $.fn.fitAjaxSubmit = function(options) {

        var defaults = {
            formId:                 "formId",
            postUrl:                "postUrl",
            redirectUrl:            "redirectUrl",
            saveBtnId:              "save_button",
            saveBtnEnableText:      "Save",
            saveBtnDisableText:     "Saving...",
            saveBoxId:              "saving-box",
            saveBoxText:            "Saving...",
            errorMsgId:             "error_messages",
            beforeSubmitFn:         function(formData, jqForm, options) {},
            successFn:              function(response) {
                if(response.success == true) {
                    window.location = options.redirectUrl + response.object_id;
                } else {
                    $('#'+options.saveBtnId).removeAttr('disabled').val(options.saveBtnEnableText);
                    $('#'+options.saveBoxId).text(options.saveBoxText).fadeOut(300);
                    $('#'+options.errorMsgId).html(errorMessages(response)).hide().fadeIn(300);
                    window.scrollTo(0,0);
                }
            }
        };

        var options = $.extend(defaults, options);

        return this.each(function() {
            $('#'+options.saveBtnId).click(function() {

                $('#'+options.saveBtnId).attr('disabled', 'disabled').val(options.saveBtnDisableText);
                $('#'+options.saveBoxId).text(options.saveBoxText).fadeIn(200);

                $('#' + options.formId).ajaxForm({
                    url: options.postUrl,
                    type: "POST",
                    dataType: "json",
                    beforeSubmit: options.beforeSubmitFn,
                    success: options.successFn
                })
            });
        });
    };
})(jQuery);