字符限制

<html>
<head>
<title> jquery完美实现textarea输入框限制字数</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("#weibo").keyup(function(){
var len = $(this).val().length;
if(len > 139){
$(this).val($(this).val().substring(0,140));
}
var num = 140 - len;
$("#word").text(num);
});
});
</script>
<style type="text/css">
h6{color:blue;}
textarea{resize:none;}
#word{color:red;}
</style>
</head>
<body>
<h6>说点什么吧,你可以输入<span>140</span>个字,现在剩余<span id="word">140</span>个</h6>
<textarea name="con" id="weibo" cols="45" rows="6"></textarea>
</body>
</html>

posted @ 2016-07-29 11:29  小林夕  阅读(242)  评论(0编辑  收藏  举报