คุณสมบัติ name ของ HTML DOM Input URL ใช้สำหรับดึงหรือกำหนดค่าของแอตทริบิวต์ name ในช่องป้อน URL
ไวยากรณ์ (Syntax)
การดึงค่า name
inputURLObject.name
การกำหนดค่า name
inputURLObject.name = 'String'
ตัวอย่างการใช้งาน
ตัวอย่างแสดงเจ้าของ URL ผ่านแอตทริบิวต์ name
<!DOCTYPE html>
<html>
<head>
<title>Input URL name</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-name</legend>
<label for="URLSelect">URL พนักงาน: <input type="url" id="URLSelect" value="https://www.example.com" name="Jack"> </label>
<input type="button" onclick="getName()" value="Who is the Owner? ">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputURL = document.getElementById("URLSelect");
function getName() {
if(inputURL.value === 'https://www.example.com')
divDisplay.textContent = 'Above URL belongs to ' + inputURL.name;
else
divDisplay.textContent = 'Above URL belongs to no one!';
}
</script>
</body>
</html>
ผลลัพธ์
ก่อนคลิกปุ่ม - ช่อง URL แสดง https://www.example.com name="Jack"
คลิก "Who is the Owner?" - แสดง "Above URL belongs to Jack"
ความสำคัญ: name ใช้ระบุช่องข้อมูลเมื่อส่งฟอร์ม (form submission) และฝั่งเซิร์ฟเวอร์จะรับค่าผ่าน name นี้