internetexplorerjavascript样式.高度不起作用

internet explorer javascript style.height not working

本文关键字:不起作用 高度 样式 internetexplorerjavascript      更新时间:2023-11-23

我正试图为一个网站创建一个cookie策略警报,就像屏幕顶部的一个栏一样简单。这个想法是用户必须点击关闭,然后栏才会消失。这个概念在谷歌chrome中运行良好,但在InternetExplorer9中,点击时不会改变其高度。

这是我的代码(我知道这是基本的,但不幸的是,这是由于机构使用的平台——

<script language=javascript type='text/javascript'> 
function hideDiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('hideShow').style.height= '0px'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideShow.height= '0px'; 
} 
else { // IE 4 
document.all.hideShow.style.height= '0px'; 
} 
} 
} 
function showDiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('hideShow').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideShow.visibility = 'visible'; 
} 
else { // IE 4 
document.all.hideShow.style.visibility = 'visible'; 
} 
} 
} 
</script> 
<style>
#hideShow{
color:white;
font-family:Gill Sans MT;
text-align:center;
font-height:20px;
</style>
<div id="hideShow" ..etc> 
My content 
<a href="javascript:hideDiv()">Close</a> 
</div> 

此外,如果有人愿意的话,你能解释一下我如何设置它,让div"hideShow"在点击之前一直显示,然后再也不会出现在那台机器上吗?

如果你需要更多的细节,请告诉我。提前感谢Rob

问题是必须在hideShow-css中定义高度。以及字体大小。然后javascript必须将height和fontSize设置为0px。