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>輸出結果
它將產生以下輸出結果 −
在點選 ‘獲取示例’ 按鈕之前 −

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

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP