我(我认为)是一个非常简单的 JS 脚本,用于根据页面 ID 显示元素。在 FF 中工作正常,但在 Chrome 或 IE 中不行
我正在使用的网站上的每个页面都有以下行:
<input id="actualPageId" type="hidden" value="xxxxxxx"></input>
(其中“xxxxxx”是该页面的唯一数值,例如“12345”)。
我的代码基本上是:
<div id="divToHide1" style="display: none;">blah blah blah</div>
<div id="divToHide2" style="display: none;">blah blah blah</div>
......
<script>
var checker = document.getElementById('actualPageId').value;
if (checker == 'xxxxxxx' ) {
document.getElementById('divToHide1').style= "display: inline";
}
if (checker == 'xxxxxxx' ) {
document.getElementById('divToHide2').style= "display: inline";
}
.......
</script>
其想法是根据actualPageID输入标记中的值确定它基于哪个页面,然后相应地取消隐藏正确的div。在 FF 中运行良好,但在任何其他浏览器中则不然。
最佳答案
直接使用显示属性。 为什么要把事情复杂化?
document.getElementById('divToHide2').style.display= "inline";
关于Javascript 在 FF 中有效,但在 Chrome 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21587103/