88284453 2011-06-24
微博上都有统计字数的功能,其实jquery可以很简单实现了,如下,变一下就成减了,即还剩多少个字,例子是加法:
<html>
<head>
<scripttype="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/
1.4.4/jquery.min.js"></script>
<title>Jquerylivecharactercountmeter</title>
<scripttype="text/javascript">
$(document).ready(function(){
$(".counter").text("0Characters");
});
$(document).keyup(function(){
vartext=$(".text_field").val();
varcounter=text.length;
$(".counter").text(counter+"Characters");
});
</script>
<styletype="text/css">
body{
margin:350px;
}
.counter{
font-weight:bold;
color:green;
}
.text_field{
border:solid#3333332px;
width:400px;
}
</style>
</head>
<body>
<h1>Jquerylivecharactercountmeter</h1>
<divclass="counter"></div>
<textareaclass="text_field"></textarea>
</body>
</html>