3

是否可以从元素中删除 maxlength 属性?我认为将其设置为 0 会起作用,但似乎 FF4 会阻止输入任何内容。http://jsfiddle.net/hMc4y/

我听说将其设置为-1确实会触发错误并且removeAttribute也不起作用。

4

2 回答 2

5

使用“removeAttribute('maxLength')”应该可以正常工作;也许令人惊讶的是,属性名称必须是maxLength带有大写“L”的“”。考虑:

<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>
于 2011-03-18T07:54:37.873 回答
1

removeAttribute 在 Firefox 3.5 和 Chrome 中都适用于我。

于 2011-03-18T07:45:12.583 回答