Jai*_*ime 34 jquery browser-detection
任何人对如何使用jquery.support测试IE6(而不是IE7)的特定内容有任何想法?
我的问题是IE6支持:仅为锚元素悬停psuedo-class,而IE7确实支持所有元素(如FF,Chrome等).所以我想做一些特殊的事情,以防浏览器不支持:悬停所有元素...因此我需要一种方法来测试这个功能.(不想使用jQuery.browser).有任何想法吗?
Fri*_*ure 55
虽然检查功能支持而不是用户代理是一个好习惯,但是没有简单的方法来检查使用JavaScript支持css属性之类的东西.我建议你按照上面的海报建议使用条件注释或使用jQuery.browser.一个简单的实现(未经过性能或错误验证)可能如下所示:
if ($.browser.msie && $.browser.version.substr(0,1)<7) {
// search for selectors you want to add hover behavior to
$('.jshover').hover(
function() {
$(this).addClass('over');
},
function() {
$(this).removeClass('over');
}
}
Run Code Online (Sandbox Code Playgroud)
在您的标记中,将.jshover类添加到您希望悬停css效果的任何元素.在你的css中,添加如下规则:
ul li:hover, ul li.over { rules here }
Run Code Online (Sandbox Code Playgroud)
scu*_*ffe 21
您可以使用Microsoft Internet Explorer特定的条件注释将特定代码应用于IE6.
<!--[if IE 6]>
Special instructions for IE 6 here... e.g.
<script>...hook hover event logic here...</script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)
小智 20
Thickbox使用
if(typeof document.body.style.maxHeight === "undefined") {
alert('ie6');
} else {
alert('other');
}
Run Code Online (Sandbox Code Playgroud)