我有一个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,.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");
- }