HTML DOM Input URL ชุดคุณสมบัติอ่านอย่างเดียว/ส่งคืนว่า Input URL สามารถแก้ไขได้หรือไม่
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
- คืนค่าบูลีน - จริง/เท็จ
inputURLObject.readOnly
- การตั้งค่า อ่านอย่างเดียว เป็นค่าบูลีน
inputURLObject.readOnly = booleanValue
ค่าบูลีน
ที่นี่ “booleanValue” สามารถเป็นดังต่อไปนี้ -
| booleanValue | รายละเอียด |
|---|---|
| จริง | กำหนดว่าฟิลด์ url อินพุตเป็นแบบอ่านอย่างเดียว |
| ผิด | กำหนดว่าช่อง URL อินพุตไม่ใช่แบบอ่านอย่างเดียวและสามารถแก้ไขได้ |
ตัวอย่าง
ให้เราดูตัวอย่างของ ป้อน URL แบบอ่านอย่างเดียว ทรัพย์สิน −
<!DOCTYPE html>
<html>
<head>
<title>Input URL readOnly</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-readOnly</legend>
<label for="URLSelect">Contact Us :
<input type="url" id="URLSelect" onclick="showErrorMsg()" value="https://www.google.com" readOnly>
</label>
<input type="button" onclick="showMessage()" value="Copy URL">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputURL = document.getElementById("URLSelect");
divDisplay.textContent = 'Above URL is read-only';
function showMessage() {
inputURL.select();
document.execCommand('copy');
divDisplay.textContent = 'URL Copied: '+inputURL.value;
}
function showErrorMsg(){
divDisplay.textContent +=', This cannot be edited.'
}
</script>
</body>
</html> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
ก่อนคลิก 'คัดลอก URL' ปุ่ม −

คลิก 'ติดต่อเรา' ฟิลด์ URL -

คลิก 'คัดลอก URL' ปุ่ม −
