使用 <form> 之外的按钮提交表单.标签 [英] Submit form using a button outside the <form> tag

查看:23
本文介绍了使用 <form> 之外的按钮提交表单.标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有:

<form method="get" action="something.php">
    <input type="text" name="name" />
</form>

<input type="submit" />

我如何使用表单外的提交按钮提交该表单,我认为在 HTML5 中有一个用于提交的 action 属性,但我不确定这是否完全跨浏览器,如果不是无论如何要做到这一点?

How do I go about submitting that form with that submit button outside of the form, I think in HTML5 theres an action attribute for the submit but I'm not sure if thats fully cross-browser and if it isn't is there anyway to do this?

推荐答案

更新:在现代浏览器中,您可以使用 表单 属性来执行此操作.

Update: In modern browsers you can use the form attribute to do this.

据我所知,没有 javascript 就无法做到这一点.

As far as I know, you cannot do this without javascript.

这是规范所说的

用于创建控件的元素通常出现在 FORM 中元素,但也可能出现在 FORM 元素声明之外当它们用于构建用户界面时.这在内在事件部分.请注意,表单外的控件不能成为成功的控制者.

The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces. This is discussed in the section on intrinsic events. Note that controls outside a form cannot be successful controls.

这是我的大胆

submit 按钮被认为是一个控件.

A submit button is considered a control.

http://www.w3.org/TR/html4/interact/forms.html#h-17.2.1

来自评论

我有一个多选项卡设置区域,带有一个按钮来更新所有内容,由于对于它的设计,按钮将在表单之外.

I have a multi tabbed settings area with a button to update all, due to the design of it the button would be outside of the form.

为什么不将 input 放在表单中,而是使用 CSS 将其放置在页面的其他位置?

Why not place the input inside the form, but use CSS to position it elsewhere on the page?

这篇关于使用 &lt;form&gt; 之外的按钮提交表单.标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆