微博上都有统计字数的功能,其实jquery可以很简单实现了,如下,变一下就成减了,即还剩多少个字,例子是加法:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/
1.4.4/jquery.min.js"></script>
<title>Jquery live character count meter</title>
<script type="text/javascript">
$(document).ready(function() {
$(".counter").text("0 Characters");
});
$(document).keyup(function() {
var text=$(".text_field").val();
var counter=text.length;
$(".counter").text(counter+" Characters");
});
</script>
<style type="text/css">
body{
margin:350px;
}
.counter{
font-weight:bold;
color:green;
}
.text_field{
border:solid #333333 2px;
width:400px;
}
</style>
</head>
<body>
<h1>Jquery live character count meter</h1>
<div class="counter"></div>
<textarea class="text_field"></textarea>
</body>
</html>
1 楼
Sunny_kaka
2011-06-26
你这也太简单了把.中午和英文是怎么算的?