Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính size của HTML DOM Input Email

Thuộc tính size của đối tượng Input Email lấy hoặc thiết lập chiều rộng hiển thị (số ký tự nhìn thấy) của trường email. Mặc định là 20 nếu không định nghĩa.

Cú pháp

Lấy giá trị size

inputEmailObject.size

Thiết lập size

inputEmailObject.size = số

Ví dụ minh họa

Tăng độ rộng hiển thị trường email từ 10 lên 30 ký tự:

<!DOCTYPE html>
<html>
<head>
<title>Input Email 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>Email-size</legend>
    <label for="EmailSelect">Email ID: <input type="email" id="EmailSelect" size="10"> </label><br>
    <input type="button" onclick="increaseVisibility()" value="Tăng độ hiển thị">
    <div id="divDisplay"></div>
  </fieldset>
</form>
<script>
  var divDisplay = document.getElementById("divDisplay");
  var inputEmail = document.getElementById("EmailSelect");
  function increaseVisibility() {
    inputEmail.size = 30;
    divDisplay.textContent = 'Độ hiển thị tăng lên: ' + inputEmail.size;
  }
</script>
</body>
</html>

Kết quả

Ban đầu ô email hiển thị 10 ký tự. Sau khi nhấn nút, mở rộng thành 30 ký tự.