我们如何在 HTML 表单中对数据进行分组?


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

语法

<fieldse>…..</fieldset>

示例 1

以下是使用 <legend> 标签在 <fieldset> 标签内对 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>

更新于:19-10-2022

4K+ 查看

开启你的 职业生涯

完成课程获得认证

入门
广告
© . All rights reserved.