代码改变世界

兼容多种浏览器的select选择事件写法

2016-05-20 13:55  sunshine1987  阅读(352)  评论(0)    收藏  举报
$('.test').attr('onChange', navigator.userAgent.indexOf('MSIE') > -1 ? "$(this).data('onChange').apply(this)" : "")
.change(function () {
if ((navigator.userAgent.indexOf('MSIE') > -1)){
//ie789
console.log('ie789');
} else{
console.log('chrome');
}
})
.data('onChange', function () {
//ie8/ie9
console.log('ie89');
});