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

WBOY
Release: 2016-06-06 20:27:57
Original
2076 people have browsed it

我想把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>
Copy after login

可以考虑ajax吧

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

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

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


提交按钮在form外面,但提交的时候会验证form里面的text的required,当然你把文本框放外面然后加form属性也可以
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!