我有一些 JavaScript 代码
var href = "demo.php";
if(href)
{
if($("#opacity")){
$("#opacity").css({
opacity: 0.5
});
}
if (document.getElementById("layer")) {
var ele = document.getElementById("layer");
ele.style.display = "block";
}
}
我想避免这些代码
if($("#opacity")){
$("#opacity").css({
opacity: 0.5
});
}
如果浏览器是IE8,则无法执行..请帮忙。 。 .
最佳答案
您可以使用jQuery.browser ,检测浏览器是否是 IE8,但这被认为是一个不好的做法:
if ($.browser.msie && $.browser.version.substr(0,1) == 8)) {
// ...
}
您应该使用jQuery.support来代替这个,它会告诉您是否可以使用opacity
:
opacity is equal to true if a browser can properly interpret the opacity style property. (It is currently false in IE, it uses alpha filters instead). CSS3 spec
if (!$.support.opacity) {
// ...
}
关于javascript - 如果浏览器是Internet Explorer,如何避免某些JavaScript代码被执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847442/