input, textarea,监听输入事件

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

原文地址:https://www.cnblogs.com/zlog/p/5387854.html