Why do i get an exception when I use JQuery's form.Submit() in IE8?

孤人 提交于 2019-12-24 23:26:09

问题


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>

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

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().

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


回答1:


change ID and name of the submit-Button.

From the docs:
Additional Notes:
Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures.




回答2:


I can't see how that would work in any browser. There is no Submit method. Javascript is case sensetive. Use submit instead.




回答3:


I don't know exactly what are you trying to do, but to submit a form, you have to do something like:

$("form").on("submit", function(event){...});

or

$("form").submit(function(event){...});

in the {...} part you validate, whatever you have to validate and if sucess, you do the ajax request:

$.ajax({...});


来源:https://stackoverflow.com/questions/8848174/why-do-i-get-an-exception-when-i-use-jquerys-form-submit-in-ie8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!