jquery - 使用 jQuery 识别 IE9/IE10

标签 jquery html internet-explorer browser-detection

我有一个 jQuery 代码,它适用于 Chrome/Mozilla 但不适用于 IE。

if ($("html").hasClass("ie")) {
    $(function(){
        $('.green-column, .red-column, .grey-column').click(function() { 
             alert ($(this).attr("data-type"));           
        });
    });
}
else {
 $(function(){
        $('.green-column, .red-column, .grey-column').click(function() { 
         $("<div title='Selected Task is:'>" + $(this).attr("data-type") + "</div>").dialog({ 
             modal: true,
             resizable: false,
             buttons: [
                {
                   text: "OK", 
                   click: function() { $( this ).dialog( "close" ); }
                }
             ]
         });
    });
});
}
</script> 
<!--[if IE 7]>    <html lang="en-us" class="ie"> <![endif]-->
<!--[if IE 8]>    <html lang="en-us" class="ie"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-us" class="ie"> <!--<![endif]-->

所以我打算为 IE9/IE10 使用警报,但我无法区分浏览器。谁能告诉我如何在 jQuery/HTML 中识别 IE9/IE10?

最佳答案

无需使用库或条件编译即可实现:

if (document.addEventListener) {
    alert("IE9 or greater");
}

if (window.requestAnimationFrame) {
    alert("IE10 or greater");
}

关于jquery - 使用 jQuery 识别 IE9/IE10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15657614/

相关文章:

html - Bootstrap 3 : How to keep thumbnails or images aligned within a row?

javascript - 如何开发和部署 IE 11 的附加组件

javascript - 使用 jquery 从 CDATA 和描述标签中获取图像

javascript - 更改选择将更改具有相同先前值的另一个选择

html - 如何将文本与 <div> 中的图像垂直对齐

html - 按类分类的 Outlook 条件样式

javascript - 子窗口如何从javascript中的父窗口继承css样式?

html - 用于生成跨浏览器工作的复选标记 li 的正确 CSS

javascript - imagesLoaded 插件无法与 Angular JS 一起使用

javascript - 我的 JS 无法处理我的 html/css。不知道为什么。 (控制台错误 'ReferenceError: $ is not defined')