Jquery提交不会触发

时间:2012-08-09 15:58:37

标签: jquery submit

我有以下代码:

<!doctype html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>StarTrackr!</title>
        <script src="../../lib/jquery-1.7.1.min.js" type="text/javascript"
        charset="utf-8"></script>
        <script type="text/javascript">
        $(document).ready(function () {

            $('div').load('1.htm');
            // The above function does work

            $("#testform").submit(function () {
                //Code after form submitted and this does not fire
                alert("hi");
            });    
        });         
        </script>
    </head>
    <body>
        <div></div>
        <form id="testform">Email:
            <input type="text" name="email" />
            <br />First Name:
            <input type="text" name="fname" />
            <br />Last Name:
            <input type="text" name="lname" />
            <br />
            <input type="button" name="submit" id="submit" value="Submit" />
        </form>
    </body>    
</html>

当我点击提交按钮时,警告(hi)应弹出,但不会。有谁知道为什么?假设正确加载了Jquery库

谢谢, 吉姆

2 个答案:

答案 0 :(得分:4)

input需要type="submit",而不是type="button"

答案 1 :(得分:0)

<input type="button" name="submit" id="submit" value="Submit" />

将type =“button”更改为type =“submit”