【问题标题】:Chrome form.submit() handler ignores required fieldsChrome form.submit() 处理程序忽略必填字段
【发布时间】:2014-03-26 16:24:21
【问题描述】:

我预计使用 javascript 在 <form> 上调用 .submit() 会调用每个 <input/> 上的验证函数,就像单击提交按钮一样。

我做错了吗?这是设计使然吗?

<form name="nameForm" action="#" method="post"
      onsubmit="this.name.value = this.name.value + ' (' + location.hostname + ')'">
  <input type="text" name="name"
         placeholder="Your name" required="required" value="" />
  <input type="submit" name="commit" value="Submit" />
</form>
<p>This form has a <code>required</code> field.</p>
<p>
  But <a href="javascript:document.nameForm.submit()">this link</a>
  which calls the form's <code>submit()</code> function doesn't fire
  the <code>required</code> handler.
</p>

在提交时忽略控制台错误。我有一个真正的提交操作。

【问题讨论】:

    标签: javascript html forms google-chrome required


    【解决方案1】:

    解决方法是从链接中调用document.nameForm.commit.click(),但我仍然不明白为什么提交操作不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2012-09-22
      相关资源
      最近更新 更多