admin管理员组

文章数量:1279234

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

I've heard that setting it to -1 does trigger an error and removeAttribute does not work either.

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

I've heard that setting it to -1 does trigger an error and removeAttribute does not work either.

Share Improve this question edited Feb 1, 2015 at 16:31 Deduplicator 45.7k7 gold badges72 silver badges123 bronze badges asked Mar 18, 2011 at 7:39 Mikulas DiteMikulas Dite 7,9419 gold badges61 silver badges102 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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.

本文标签: javascriptRemoving the maxlength attributeStack Overflow