使用jQuery识别IE9 / IE10

前端之家收集整理的这篇文章主要介绍了使用jQuery识别IE9 / IE10前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个jQuery代码,适用于Chrome / Mozilla但不适用于IE.
  1. if ($("html").hasClass("ie")) {
  2. $(function(){
  3. $('.green-column,.red-column,.grey-column').click(function() {
  4. alert ($(this).attr("data-type"));
  5. });
  6. });
  7. }
  8. else {
  9. $(function(){
  10. $('.green-column,.grey-column').click(function() {
  11. $("<div title='Selected Task is:'>" + $(this).attr("data-type") + "</div>").dialog({
  12. modal: true,resizable: false,buttons: [
  13. {
  14. text: "OK",click: function() { $( this ).dialog( "close" ); }
  15. }
  16. ]
  17. });
  18. });
  19. });
  20. }
  21. </script>
  22. <!--[if IE 7]> <html lang="en-us" class="ie"> <![endif]-->
  23. <!--[if IE 8]> <html lang="en-us" class="ie"> <![endif]-->
  24. <!--[if gt IE 8]><!--> <html lang="en-us" class="ie"> <!--<![endif]-->

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

解决方法

可以在不使用库或条件编译的情况下实现:
  1. if (document.addEventListener) {
  2. alert("IE9 or greater");
  3. }
  4.  
  5. if (window.requestAnimationFrame) {
  6. alert("IE10 or greater");
  7. }

猜你在找的jQuery相关文章