Tec*_*ech 3 html javascript maxlength
我只是想知道我们是否可以从javascript获取输入字段的最大长度
<input type="password" id="password" maxlength="20" >
Run Code Online (Sandbox Code Playgroud)
我尝试了这个,但它返回undefined
console.log(document.getElementById("password").maxlength);
Run Code Online (Sandbox Code Playgroud)
使用DOMElement::getAttribute()获得的属性,在一个DOMElement没有上市,但现有的标记:
var el = document.getElementById("password");
console.log(el.getAttribute('maxlength'));
Run Code Online (Sandbox Code Playgroud)
document.getElementById("password").maxLength
Run Code Online (Sandbox Code Playgroud)
要使用Javascript访问它,您需要一个大写的'L'