HTML DOM 輸入 URL placeholder 屬性


HTML DOM 輸入 URL placeholder 屬性設定/返回一個字串,通常用於向用戶提示輸入文字的外觀。

語法

以下是語法 −

  • 返回字串值
inputURLObject.placeholder
  • placeholder 設定為 stringValue
inputURLObject.placeholder = stringValue

示例

讓我們看一個輸入 URL placeholder 屬性的示例 −

 線上演示

<!DOCTYPE html>
<html>
<head>
<title>Input URL placeholder</title>
<style>
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   * {
      padding: 2px;
      margin:5px;
   }
   input[type="button"] {
      border-radius: 10px;
   }
</style>
</head>
<body>
<form>
<fieldset>
<legend>URL-placeholder</legend>
<label for="URLSelect">URL:
<input type="url" id="URLSelect">
</label>
<input type="button" value="Get an Example" onclick="setPlaceholder()">
</fieldset>
</form>
<script>
   var inputURL = document.getElementById("URLSelect");
   function setPlaceholder() {
      inputURL.placeholder = 'https://www.google.com';
   }
</script>
</body>
</html>

輸出結果

它將產生以下輸出結果 −

在點選 ‘獲取示例’ 按鈕之前 −

在點選“獲取示例”按鈕之後 −

更新於: 30-Jul-2019

131 瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始使用
廣告