3

我在页面上有一个简单的表单,我想在发生某些事件时自动提交它。

下面的测试代码尝试在页面加载后立即提交表单,但失败了。Firebug 说“H[G] 不是函数”。H[G] 似乎是“提交”。

我做的事情真的很愚蠢吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>test</title>
</head>
<body>
    <form action="/test.php" method="post" id="packingform">
        <input name="bob" value="1" type="text" />
        <input type="submit" name="submit" value="hello" />
    </form>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript">
    // <![CDATA[
    $(document).ready(function() 
    {
        // This line fails with an error and the form is not submitted
        $("#packingform").submit();
    }
    );
    // ]]>
    </script>
</body>
</html>
4

5 回答 5

9

知道了。

事实证明,如果您的表单中有一个命名的提交按钮,则 submit() 将失败。这是关于 jquery 的错误报告的链接:http: //dev.jquery.com/ticket/4652

解决方案是更改<input type="submit" name="submit" value="hello" />
<input type="submit" value="hello" />

我希望这对其他人有帮助...

于 2009-07-07T10:11:54.163 回答
0

问题似乎出action="/test.php"在 Firefox 上,因为它适用于 Chrome 和 IE

尝试将其更改为action="test.php"并重试。

于 2009-07-07T10:01:45.773 回答
0

我的猜测是您的 jQuery.js 文件有问题。也许尝试用从jQuery 网站下载的新副本替换 jQuery.js 文件。

于 2009-07-07T10:11:34.897 回答
0

嗨,这确实非常有帮助,我浪费了大约 16 个小时来查看发生了什么,解决方案是更改提交按钮的名称谢谢

于 2009-07-17T12:01:52.080 回答
0

我有类似的问题,我的提交按钮没有“名称”,它只有“id”。

无论如何,这解决了我的问题:

$("#submitButton").click();
于 2014-02-05T20:51:02.777 回答