触发ie8的jquery事件
我想为ie8或更低版本触发一个javascript事件。这是我的标记:触发ie8的jquery事件,jquery,internet-explorer-8,Jquery,Internet Explorer 8,我想为ie8或更低版本触发一个javascript事件。这是我的标记: <!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie10 lt-ie9 lt-ie8"> <![endi
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie10 lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie10 lt-ie9"> <![endif]-->
<!--[if IE 9]> <html class="no-js lt-ie10"> <![endif]-->
<!--[if gt IE 9]><!--> <html class="no-js"> <!--<![endif]-->
...
</html>
但这在任何浏览器中都毫无用处
正确的方法是什么?在document ready上,您可以检查html元素是否具有特定的IE类,然后执行以下操作:
$( document ).ready(function() {
if ($('html').hasClass('lt-ie9')) {
alert('ie8 only');
}
});
你可能不想这样做。但它应该起作用
$( document ).ready(function() {
if($('html').hasClass('lt-ie9')) {
// later than IE9 only...
}
});
我建议您使用功能检测而不是浏览器检测。您使用的是哪个版本的jquery?2.x放弃了对IEGood idea的支持,但我使用的是1.11,所以不是这样代码>改为尝试在上使用。但事实证明load()在1.8中已被弃用。将编辑问题是的,谢谢,我想这就是我需要的!
$( document ).ready(function() {
if($('html').hasClass('lt-ie9')) {
// later than IE9 only...
}
});