说我有一个这样定义的id
<span id ="radiobuttonContainer"> Check to enable checkboxes:
<input type="radio" name="cov-failed" value="cover" onclick="javascript:printoutCheckboxes('cover')">
Coverage
<input type="radio" name="cov-failed" value="failed" onclick="javascript:printoutCheckboxes('failed')">
Failed</span>
我不想在 I.E 9 以下的浏览器中显示此“spanId”,因为这可以使 IE < 8 无法管理的数据更加可视化。我知道你可以有不同的 javascripts 和 css:es,这取决于像这样的浏览器
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="root/include/excanvas.min.js"></script><![endif]-->
然后选择display: 'none';
但我想知道除了这一行之外是否真的有 2 个包含完全相同信息的相等 .css 文件?
我不能做这样的事情吗?
<!--[if lte IE 8]>document.getElementById('radiobuttonContainer').style.display = 'none';<![endif]-->
最佳答案
您应该能够将标签包裹在条件注释中。或者,由于页面中包含的内联 CSS 优先于包含的 CSS,因此您不必包含第二个样式表,只需包含一个特定于该情况的新定义。即
<!--[if lte IE 8]>
<style type="text/css">
#radiobuttonContainer{
display = 'none';
};
<![endif]-->
并将它放在包含的 CSS 文件之后。
关于javascript - 是否可以在某些浏览器中隐藏 id 元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6440511/