คุณสมบัติตัวยึดตำแหน่ง HTML DOM Input URL ตั้งค่า/ส่งคืนสตริงที่โดยทั่วไปใช้เพื่อให้คำแนะนำแก่ผู้ใช้ว่าข้อความอินพุตจะมีลักษณะอย่างไร
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
- คืนค่าสตริง
inputURLObject.placeholder
- การตั้งค่า ตัวยึดตำแหน่ง เป็น stringValue
inputURLObject.placeholder = stringValue
ตัวอย่าง
ให้เราดูตัวอย่างของคุณสมบัติตัวยึดตำแหน่ง Input URL -
<!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> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
ก่อนคลิก 'รับตัวอย่าง' ปุ่ม −

หลังจากคลิก 'รับตัวอย่าง' ปุ่ม −
