jquery统制文本框输入数字变化后做操作

jquery控制文本框输入数字变化后做操作

1.最简单方式绑定onkeyup事件

2.jQuery.fn.extend({

propertychange: function(fn) {

if (!+ [1, ] != true) {

$(this).get(0).addEventListener("input", fn, false)

}

$(this).bind("propertychange", fn);

return this

}

});

 

以下是例子:

 

<!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>