如何在 HTML 表单中分组数据?

htmlweb developmentfront end technology更新于 2024/6/7 9:16:17

我们使用 <fieldset> 标签在 HTML 表单中对相关数据进行分组。此标签会在网页上相关元素周围创建一个框。<legend> 标签用于 <fieldset> 标签内部,为分组添加标题或名称。

语法

<fieldset>…..</fieldset>

示例 1

以下示例使用 <fieldset> 标签内的 <legend> 标签对 HTML 表单中的数据进行分组 -

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="description" content="meta tag in the web document"> <meta name="keywords" content="HTML,CSS"> <meta name="author" content="lokesh"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form> <fieldset> <legend>Employee Details</legend> Employee Name<br> <input type="text" name="Ename"> <br> Employee ID<br> <input type="text" name="Eid"> <br> Employee Address<br> <input type="text" name="Eid"> <br> </fieldset> </form> </body> </html>

示例 2

您可以尝试运行以下代码来对 HTML 表单中的数据进行分组 -

<!DOCTYPE html> <html> <body> <form> <fieldset> <legend>Student Information:</legend> Student Name:<br> <input type="text" name="sname"> <br> Student Subject:<br> <input type="text" name="ssubject"> <br> </fieldset> </form> </body> </html>

相关文章


有用资源