HTMLplaceholder 屬性


<input> 元素的 placeholder 屬性用於設定輸入項的提示,簡要描述在該特定輸入項中預期輸入的內容。此屬性適用於以下型別的輸入:text、url、search、email、password 和 tel。它在 HTML5 中引入。

以下是語法 −

<input placeholder="placeholder_text">

在這裡,placeholder_text 是簡要的提示,即佔位符,當用戶訪問該網頁時,它們會看到此佔位符。

現在讓我們看一個示例以實現 <input> 元素的 placeholder 屬性 −

示例

 線上演示

<!DOCTYPE html>
<html>
<body>
<h2>Register</h2>
<form action="" method="get">
   Id − <input type="text" name="id" placeholder="Enter UserId here..."><br>
   Password − <input type="password" name="pwd" placeholder="Enter password here..."><br>
   DOB − <input type="date" name="dob"><br>
   Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..."><br>
   Email − <input type="email" name="email" placeholder="Enter email here..."><br><br>
   <button type="submit" value="Submit">Submit</button>
</form>
</body>
</html>

輸出

在上面的示例中,我們提供了一個帶有一些欄位的表單 −

<form action="" method="get">
   Id − <input type="text" name="id" placeholder="Enter UserId here..."><br>
   Password − <input type="password" name="pwd" placeholder="Enter password here..."><br>
   DOB − <input type="date" name="dob"><br>
   Telephone − <input type="tel" name="tel" placeholder="Enter mobile number here..."><br>
   Email − <input type="email" name="email" placeholder="Enter email here..."><br><br>
   <button type="submit" value="Submit">Submit</button>
</form>

所有欄位均設定了佔位符,如下所示 −

<input type="password" name="pwd" placeholder="Enter password here...">

只需使用 placeholder 屬性並設定簡要提示 −

placeholder="Enter password here..."

更新於: 30-Jul-2019

367 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告