我們如何在 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.