js限制文本框输入字数

//js代码

<script type="text/javascript">        

function checkLen(term){        

document.all.termLen.value=30-term.value.length;        

if (document.all.termLen.value<=0){          t

erm.value=term.value.substring(0,30);         }         } 

</script>

//html代码

<table border="0" width="98%"> 

<tr>       

<td colspan="2" align="center">  <textarea id="txtLookReason" style="width: 99%; height: 100px; margin-top:5px;" onKeyPress="checkLen(this)" onKeyUp="checkLen(this)" onChange="checkLen(this)"></textarea> </td></tr>        

</table>          

<span class="color_red">(限30字以内,您还可以输入<input name="termLen" value="30" style="background-color:#FFFFFF; font-size:9pt; color:#FF3333; border:0; text-align:right" size="3" readonly />   字)</span>

posted @ 2013-10-17 13:34  D调灬仔  阅读(2163)  评论(0编辑  收藏  举报

作者D调灬仔

出处:https://www.cnblogs.com/chj929555796/

如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!