为什么form.submit()没有起作用?

3

我在一个页面中有以下片段。我无法弄清楚为什么单击button1元素时表单没有提交。在IE中,我会收到错误提示,指出该对象不支持此属性或方法。我将document.poform放入一个警报中,它会警报一个表单对象。我感觉可能是我漏掉了一些非常明显的东西?

<pre>
<?
    var_dump($_POST);
?>
</pre>
<form action="" method="post" name="poform">
    <input name="test" type="text" />
    <input name="button" type="button" value="button1" onclick="document.poform.submit();" />
    <input name="submit" type="submit" value="button2" />
</form>

@Gabe:没有操作意味着“将表单提交到加载表单的相同网址”。 - Marc B
@Gabe 定义无操作只是提交给自身。 - dqhendricks
2个回答

8
由于您有一个名为“submit”的<input>,所以document.poform.submit是该<input>,而不是submit()方法。请使用其他名称。

实际上,不要使用document.poform - 给它一个ID并通过document.getElementById('whatever')访问它。 - jimbo

-2

将 type="button" 改为 type="submit"


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接