HTMLTextAreaElement: minLength property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

Thuộc tính minLength của giao diện HTMLTextAreaElement cho biết số ký tự tối thiểu (tính theo UTF-16 code units) cần có để giá trị của phần tử <textarea> hợp lệ. Nó phản ánh thuộc tính minlength của phần tử. -1 có nghĩa là không có yêu cầu độ dài tối thiểu.

Note: Nếu textarea có giá trị và giá trị đó có ít ký tự hơn mức thuộc tính minlength yêu cầu, phần tử được coi là không hợp lệ và thuộc tính ValidityState của tooShort sẽ là true.

Giá trị

Một số đại diện cho minlength của phần tử nếu có, hoặc -1.

Ví dụ

Với HTML sau:

html
<p>
  <label for="comment">Comment</label>
  <textarea id="comment" minlength="10" maxlength="200"></textarea>
</p>

Bạn có thể dùng thuộc tính minLength để lấy hoặc đặt giá trị thuộc tính minlength của <textarea>:

js
const textareaElement = document.querySelector("#comment");
console.log(`Element's minLength: ${textareaElement.minLength}`); // "Element's minlength: 10"
textareaElement.minLength = 5; // updates the element's minlength attribute value

Đặc tả kỹ thuật

Specification
HTML
# dom-textarea-minlength

Tương thích trình duyệt

Xem thêm