Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

คุณสมบัติ HTML DOM Input URL size

คุณสมบัติ size ของ HTML DOM Input URL ใช้สำหรับดึงหรือกำหนดความกว้างที่มองเห็นได้ของช่องป้อน URL (วัดเป็นจำนวนตัวอักษร) ค่าเริ่มต้นคือ 20

ไวยากรณ์ (Syntax)

การดึงค่า size

inputURLObject.size

การกำหนดค่า size

inputURLObject.size = number

ตัวอย่างการใช้งาน

ตัวอย่างเพิ่มขนาดช่องป้อน URL

<!DOCTYPE html>
<html>
<head>
<title>Input URL size</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-size</legend>
    <label for="URLSelect">URL: <input type="url" id="URLSelect" size="10"> </label><br> 
    <input type="button" onclick="increaseVisibility()" value="Increase Visibility"> 
    <div id="divDisplay"></div> 
  </fieldset> 
</form> 
<script> 
  var divDisplay = document.getElementById("divDisplay"); 
  var inputURL = document.getElementById("URLSelect"); 
  function increaseVisibility() { 
    inputURL.size = 30; 
    divDisplay.textContent = 'Visibility Increased to ' + inputURL.size; 
  } 
</script> 
</body>
</html>

ผลลัพธ์

ก่อนคลิกปุ่ม - ช่อง URL กว้าง 10 ตัวอักษร

หลังคลิก "Increase Visibility" - ช่อง URL ขยายเป็น 30 ตัวอักษร

หมายเหตุ: size ส่งผลต่อการแสดงผลเท่านั้น ไม่จำกัดความยาว URL ที่ป้อนได้จริง (ใช้ maxlength)