是否可以从元素中删除 maxlength 属性? 我认为将其设置为 0 会起作用,但 FF4 似乎会阻止输入任何内容。 http://jsfiddle.net/hMc4y/
我听说将其设置为 -1
确实会触发错误,而且 removeAttribute
也不起作用。
最佳答案
使用“removeAttribute('maxLength')”应该没问题;也许令人惊讶的是,属性名称必须是带有大写字母“L”的“maxLength
”。考虑:
<form name="f">
<input name="t" type="text" maxlength="5"/>
</form>
<script type="text/javascript">
var t = document.f.t;
alert(t.maxLength); // 5
t.removeAttribute('maxLength');
alert(t.maxLength); // 524288 (on Chrome/10.0.648.134)
</script>
关于javascript - 删除 maxlength 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5349265/