美国女子宠物狗遭邻居开枪打死 当场大声痛哭失落不已

Baseline Widely available
百度 其实,她的两次怀孕都成功骗过了身边朋友,当有人指着她的肚子问是否怀孕时,雷某总以胖为借口掩盖了过去。

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

The read-only tooLong property of the ValidityState interface indicates if the value of an <input> or <textarea>, after having been edited by the user, exceeds the maximum code-unit length established by the element's maxlength attribute.

Value

A boolean that is true if the ValidityState does not conform to the constraints.

Examples

Textarea with too long character count

The following example checks the validity of a textarea element. A constraint has been added using the maxlength attribute so the textarea expects a maximum of 10 characters. If there are too many characters in the textarea (which is true below), the element fails constraint validation, and the styles matching :invalid CSS pseudo-class are applied.

When editing the textarea, the browser will not allow the user to add characters that would fail constraint validation of maximum character count, so at first, only deleting characters is allowed. Newline characters are normalized and count as a single character in the maximum length calculation.

css
textarea:invalid {
  outline: red solid 3px;
}
html
<pre id="log">Validation logged here...</pre>
<textarea name="story" id="userText" maxlength="10" rows="5">
It was a dark and


stormy night...
</textarea>
js
const userInput = document.getElementById("userText");
const logElement = document.getElementById("log");

function log(text) {
  logElement.innerText = text;
}

userInput.addEventListener("input", () => {
  userInput.reportValidity();
  if (userInput.validity.tooLong) {
    log("Too many characters in the textarea.");
  } else {
    log("Input is valid…");
  }
});

Specifications

Specification
HTML
# dom-validitystate-toolong-dev

Browser compatibility

See also