js input监听兼容事件

$('#phoneNumber').on('input',function() {
var valueP = $(this).attr('value');
if(valueP.length == 11){
$('#getVerCode').removeClass('unclick');
$('.getVerCodeJ').css('display','none');
}
else{
$('#getVerCode').addClass('unclick');
$('.getVerCodeJ').css('display','block');
}
});

//for ie
if(document.all){
$('#phoneNumber').each(function() {
var that=this;

if(this.attachEvent) {
this.attachEvent('onpropertychange',function(e) {
if(e.propertyName!='value') return;
$(that).trigger('input');

var valueP = $(this).attr('value');
if(valueP.length == 11){
$('#getVerCode').removeClass('unclick');
$('.getVerCodeJ').css('display','none');
}
else{
$('#getVerCode').addClass('unclick');
$('.getVerCodeJ').css('display','block');
}
});
}
})
}
原文地址:https://www.cnblogs.com/wangqiao170/p/6740255.html