我想为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"> <![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>和jquery:
$( document ).ready(function() {
$("html.lt-ie9").load(function(){
alert('ie8 only');
});
});但这在任何浏览器中都是一事无成。
正确的方法是什么?
发布于 2014-05-02 09:41:11
在文档准备就绪时,只需检查html元素是否具有特定的IE类,然后执行以下操作:
$( document ).ready(function() {
if ($('html').hasClass('lt-ie9')) {
alert('ie8 only');
}
});发布于 2014-05-02 09:43:06
你可能不想这样做,像这样。但这应该管用。
$( document ).ready(function() {
if($('html').hasClass('lt-ie9')) {
// later than IE9 only...
}
});我建议您使用特征检测而不是浏览器检测。
https://stackoverflow.com/questions/23424890
复制相似问题