首页 > 其他 > 详细

input, textarea,监听输入事件

时间:2016-04-13 18:24:11      阅读:152      评论:0      收藏:0      [点我收藏+]

IE使用‘propertychange‘事件监听,
其它浏览器使用‘input‘事件
测试了IE7-10, Chrome, FF, 输入没有问题.
♥但在IE9下,  删除,  回退,  Ctrl+X 没有监听到!

var $input = $(‘#textinput‘);
var $span = $(‘#num‘);
var customLength = 40;

var pressHandle = function(){
  var txtLen = $input.val().length;
  if (txtLen <= customLength) {
    $span.removeClass(‘textRed‘).addClass(‘textBlack‘).html(txtLen);
  } else{
    $span.removeClass(‘textBlack‘).addClass(‘textRed‘).html(txtLen);
  };
};

$input.bind(‘propertychange input‘, pressHandle);

在线DEMO: http://output.jsbin.com/jaladafene

 

input, textarea,监听输入事件

原文:http://www.cnblogs.com/zlog/p/5387854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!