【问题标题】:Intercepting a form with JQuery fails in IE在 IE 中使用 JQuery 拦截表单失败
【发布时间】:2012-07-19 08:39:22
【问题描述】:

我正在使用 JQuery 截取表单,但它在任何版本的 IE 中都不起作用。有没有人有任何提示?我尝试了 form.submit() 但发现它在 Firefox 中存在问题。任何帮助将不胜感激。

$(document).ready(function() {
    $("form").submit(function(e) {
        if (e.originalEvent.explicitOriginalTarget.id == "myButton") {
            if (some status is true continue to submit the form)
                return true;
                //If the status above is false continue to prompt the user if they want to submit or not
            var ok = confirm('Do you really want to save your data?');
            if (ok) {                
                return true;
            }
            else {
                //Prevent the submit event and remain on the screen
                e.preventDefault();
                return false;
            }
        }
    });

    return;
});

【问题讨论】:

  • e.originalEvent.explicitOriginalTarget 在 IE 中可用吗?
  • e.explicitOriginalTarget 是 Mozilla 特有的。
  • 我没有专门使用该代码,但非常相似。只需返回 true 即可发送表单,如果出现错误则阻止默认设置。
  • 试试 e.stopPropogation 或检查stackoverflow.com/questions/4479216/…
  • 你有任何名称为“提交”的输入元素,这可能是问题

标签: javascript jquery forms internet-explorer submit


【解决方案1】:

您是否尝试以某种方式附加到按钮的单击事件?我在这里的示例中选择了一个任意选择器。

$(".submit").click(function(e) {
    if (e.target.id === "go1") {
        alert("we're good!");
        return true;
    }

    e.preventDefault();
    return false;
});

这是一个 jsfiddle:http://jsfiddle.net/qRbQe/

由于e.originalEvent.explicitOriginalTarget 是 Mozilla 特定的,并且旨在供插件开发人员而非 Web 应用程序开发人员使用,我认为没有办法做到这一点,因为您没有获得触发处理submit 事件时的事件。

【讨论】:

    猜你喜欢
    • 2013-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    相关资源
    最近更新 更多