我們如何在 HTML 表單中獲取密碼輸入?
在 HTML 中獲取密碼輸入,要使用 <input> 標籤,將其 type 屬性指定為 password。這會隱藏密碼集中的字元。這也是單行文字輸入。
語法
<form> <input type="password" name="name… " value=" ">Male </form>
示例 1
以下示例說明如何獲取 HTML 中的密碼輸入:−
<!DOCTYPE html> <html> <body> <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> <p>Branch</p> <form> <input type="password" id="CSE" name="Branch" value="CSE" > <label for="CSE">Enter password</label> <br> <input type="password" name="Branch" value="IT" > <label for="CSE">Re-enter password</label> </form> </body> </html>
示例 2
以下提供另一個獲取密碼輸入的示例。你可以嘗試執行以下程式碼:−
<!DOCTYPE html> <html> <body> <head> <title>HTML Forms</title> </head> <p>Add your details:</p> <form> Student Username:<br> <input type="text" name="name"> <br> Password:<br> <input type="password" name="password"> <br> </form> </body> </html>
廣告