首页 > 代码库 > textarea 限制输入字数

textarea 限制输入字数

?
1
2
3
4
5
6
7
8
<script type="text/javascript">
        function limitChars(id, count) {
            var obj = document.getElementById(id);
            if (obj.value.length > count) {
                obj.value = http://www.mamicode.com/obj.value.substr(0, count);
            }
        }
    </script>

  HTML代码:

  <div>
        内容:<br />
        <textarea name="contid" runat="server" rows="2" cols="20" id="txtProcIdea" onkeydown="limitChars(‘txtProcIdea‘, 10)" 
            onchange="limitChars(‘txtProcIdea‘,10)" style="height: 49px; width: 580px;"></textarea>
    </div>