开发者

Removing the maxlength attribute

is it possible to remove a maxlength attribute from an element? I thought that setting it to 0 would work, but it seems like FF4 then prevents entering anything. http://jsfiddle.net/hMc4y/

I've开发者_开发知识库 heard that setting it to -1 does trigger an error and removeAttribute does not work either.


Using "removeAttribute('maxLength')" should work fine; perhaps the surprise is that the attribute name must be "maxLength" with an uppercase "L". Consider:

<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>


removeAttribute works for me in both Firefox 3.5 and Chrome.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜