【问题标题】:Why is form.submit() not working?为什么 form.submit() 不起作用?
【发布时间】:2011-07-18 16:46:26
【问题描述】:

我在页面中有以下片段。我一生都无法弄清楚为什么单击 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:无操作意味着“提交到加载表单的相同 url”。
  • @Gabe 定义没有任何操作只是提交给自己。

标签: javascript html


【解决方案1】:

由于您有一个名为 submit&lt;input&gt;document.poform.submit&lt;input&gt;,而不是 submit() 方法。

使用不同的名称。

【讨论】:

  • 事实上,不要做 document.poform - 给它一个 ID 并通过 document.getElementById('whatever') 访问它
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    相关资源
    最近更新 更多