表单的HTML输入栏外 [英] HTML input field OUTSIDE of a form
问题描述
我有一个带有一组输入的表单,我希望当其中一个输入更改时刷新页面.我在页面的另一侧有第二组输入,而css布局不方便我将它们放在相同的<form>
</form>
标记中.我想知道是否有一种方法可以确保位于<form>
标记之外的那些输入"仍与该表单相关联.
I have a form with a set of inputs, and I want my page to refresh when one of them changes. I have a second set of inputs on the OTHER side of the page, and the css layout doesn't make it convenient for me to put them in the same <form>
</form>
tag. I was wondering if there is a way that I can make sure those "inputs" that are located outside of the <form>
tag are still associated with that form.
是否可以通过某种方式为输入分配表单ID"?
Is there some way we can assign a "form id" to the inputs?
推荐答案
In HTML5, you can use the form
attribute:
默认情况下,与表单相关的元素与其祖先的form元素相关联,但是可以指定一个form属性来覆盖它.
A form-associated element is, by default, associated with its ancestor form element, but may have a form attribute specified to override this.
如果与表单相关的元素指定了表单属性,则该属性的值必须是元素所有者文档中表单元素的ID.
If a form-associated element has a form attribute specified, then that attribute's value must be the ID of a form element in the element's owner Document.
示例:
<form id="myform">
<input id="something" type="text">
</form>
<button form="myform" type="submit">Submit that form over there</button>
但是,您应该确保用户清楚这些在视觉上分隔开的表单元素实际上已连接.
You should however make sure that it is clear to the user that these visually separated form elements are in fact connected.
这篇关于表单的HTML输入栏外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!