当我在IE8中使用JQuery的form.Submit()时,为什么会出现异常? [英] Why do i get an exception when I use JQuery's form.Submit() in IE8?

查看:311
本文介绍了当我在IE8中使用JQuery的form.Submit()时,为什么会出现异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下在FF和Chrome上完美运行。什么是IE8抱怨?

The following works perfectly fine on FF and Chrome. What is IE8 complaining about?

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js" type="text/javascript"></script>
        <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js" type="text/javascript"></script>
    </head>
    <body>
        <form action="http://www.thisurlisfake.com" id="myForm" method="post">
            <input type="text" id="myText" class="required" />
            <input type="submit" id="submit" name="submit" />
        </form>
        <script language="javascript" type="text/javascript">
            jQuery(document).ready(function () {
                jQuery("#myForm").validate(
                {
                    submitHandler: function (form) {
                        form.Submit();
                    }
                });
            })
        </script>
    </body>
</html>

如果您未在文本框中输入任何内容,则JQuery验证将起作用并显示警告消息。

If you do NOT input anything into the textbox the JQuery Validation works and displays a warning message.

如果你在文本框中添加了一些内容,那么JQuery Validation会成功并调用我的submitHandler代码。显然我已经删除了所有额外的逻辑,但基本上最后它假设调用form.Submit()。

If you DO put something into the textbox the JQuery Validation succeeds and calls my submitHandler code. Obviously I've removed all my extra logic but basically at the end its suppose to call form.Submit().

但是,这一行form.Submit(); 生成错误:对象不支持此属性或方法

HOWEVER, this line "form.Submit();" generates "Error: Object doesn't support this property or method"

推荐答案

更改 ID 名称

来自 docs

附加说明:

表格并且它们的子元素不应使用与表单属性冲突的输入名称或id,例如submit,length或method。名称冲突可能导致令人困惑的失败。

这篇关于当我在IE8中使用JQuery的form.Submit()时,为什么会出现异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆