Home  >  Article  >  Backend Development  >  javascript - 将submit放在form标签之外如何实现表单的提交

javascript - 将submit放在form标签之外如何实现表单的提交

WBOY
WBOYOriginal
2016-06-06 20:27:572098browse

我想把submit的按钮放在form标签之外,怎么把实现数据的提交

回复内容:

我想把submit的按钮放在form标签之外,怎么把实现数据的提交

<code class="html"><form action="https://www.baidu.com/s" method="GET" name="hello" id="world">
<input type="text" name="wd" value="Hello">
</form>
<hr>
下面的是在表单外面的...
<input type="submit" onclick="document.forms['hello'].submit();" value="提交1">
<input type="submit" onclick="document.forms['world'].submit();" value="提交2"></code>

可以考虑ajax吧

用button,再写个js事件。满足你。

<code class="html">//在form表单外
<div id="submit">表单提交</div></code>
<code class="javascript"><script>
      $('#submit').click(function() {
        $('form').submit();
      });
</script></code>

不考虑兼容性的话。表单元素都加了个form属性,就算不是在form内,也会绑定的
补充:


提交按钮在form外面,但提交的时候会验证form里面的text的required,当然你把文本框放外面然后加form属性也可以
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn