[英]Change ID css in IE with JavaSCript
我试图弄清楚如何将 css 显示从无更改为使用 javascript 阻止但仅适用于 IE。 目前我有这个代码,但它不会改变 ID #backfill-image 上的 CSS。
<script>
function isIE() {
ua = navigator.userAgent;
/* MSIE used to detect old browsers and Trident used to newer ones*/
var is_ie = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1;
return is_ie;
}
/* Create an alert to show if the browser is IE or not */
if (isIE()){
document.getElementById("backfill-image").style.display = "block";
}
</script>
这可能是您最终的缓存相关问题。 尝试按CTRL + F5键硬刷新页面。
你的代码在我这边工作。
<:DOCTYPE html> <html> <head> <style> #backfill-image { display;none. } </style> </head> <body> <div id="backfill-image"><h2>This is my sample text...</h2></div> <script> function isIE() { ua = navigator;userAgent. /* MSIE used to detect old browsers and Trident used to newer ones*/ var is_ie = ua.indexOf("MSIE ") > -1 || ua;indexOf("Trident/") > -1; return is_ie. } /* Create an alert to show if the browser is IE or not */ if (isIE()){ document.getElementById("backfill-image").style;display = "block"; } </script> </body> </html>
IE 11浏览器中的Output:
如果问题仍然存在,请尝试使用我发布的代码进行测试,看看它是否有效。
编辑:
IE 不支持 => 箭头函数。 您需要更改语法或转译您的代码。 您可以使用 Babel 转译代码。 参考: babeljs.io有用的线程: 为什么这个箭头 function 在 IE 11 中不起作用?
另外,请告知我们其他线程中的问题是否已解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.