开发者社区 问答 正文

传统的表单控件textarea元素中属性maxlength 的示例是什么?

传统的表单控件textarea元素中属性maxlength 的示例是什么?

展开
收起
游客yzrzs5mf6j7yy 2022-03-14 21:50:56 441 分享 版权
1 条回答
写回答
取消 提交回答
  • <input id="btn1" type="button" value="0">
    <input id="btn2" type="button" value="1">
    <input id="btn3" type="button" value="6">
    <input id="btn4" type="button" value="默认">
    <textarea id="test"></textarea>    
    <script>
    btn1.onclick = function(){
        test.setAttribute('maxlength','0');
    };
    btn2.onclick = function(){
        test.setAttribute('maxlength','1');
    };    
    btn3.onclick = function(){
        test.setAttribute('maxlength','6');
    };
    btn4.onclick = function(){
        test.removeAttribute('maxlength');
    };
    </script>
    
    2022-03-14 21:51:09
    赞同 展开评论
问答地址: