我只是想知道,如果我们能得到从JavaScript输入字段的最大长度
<input type="password" id="password" maxlength="20" >
我试过,但它返回undefined
console.log(document.getElementById("password").maxlength);
使用DOMElement::getAttribute()
获得的属性,在一个DOMElement没有上市,但现有的标记:
var el = document.getElementById("password");
console.log(el.getAttribute('maxlength'));
该接受的答案其实是错误的:
document.getElementById("password").maxLength
将让你的maxLength
属性如maxLength="2"
,让你必须得到公正的价值:
document.getElementById("password").maxLength.value /* <-- note .value */