Why do i get an exception when I use JQuery's

2019-08-22 16:22发布

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"

3条回答
别忘想泡老子
2楼-- · 2019-08-22 16:30

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({...});
查看更多
迷人小祖宗
3楼-- · 2019-08-22 16:38

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

查看更多
乱世女痞
4楼-- · 2019-08-22 16:52

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.

查看更多
登录 后发表回答