表单外部的 HTML 输入字段 [英] HTML input field OUTSIDE of a form

查看:40
本文介绍了表单外部的 HTML 输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一组输入的表单,我希望我的页面在其中一个更改时刷新.我在页面的另一侧有第二组输入,css 布局不方便我将它们放在相同的 <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?

推荐答案

在 HTML5 中,您可以使用 form 属性:

In HTML5, you can use the form attribute:

默认情况下,与表单相关的元素与其祖先表单元素相关联,但可以指定一个表单属性来覆盖它.

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屋!

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