jquery输入文字,实时字数提示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.fn.extend({
propertychange: function(fn) {
if (!+ [1, ] != true) {
$(this).get(0).addEventListener("input", fn, false)
}
$(this).bind("propertychange", fn);
return this
}
});
</script>
</head>
<body>
<input id="setCont" type="text" value='啊啊'/><span id="count">5</span>
<script>
$('#setCont').propertychange(function(){
var t = this;
$('#count').text(t.value.length);
});
</script>

</body>
</html>

以上是栗子!

posted @ 2012-02-20 09:11  FaceSun  阅读(797)  评论(0编辑  收藏  举报