首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

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

2012-09-04 
jquery控制文本框输入数字变化后做操作1.最简单方式绑定onkeyup事件2.jQuery.fn.extend({propertychange:

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>

热点排行