我正试图在点击时显示谷歌地图。java脚本更改了它的显示属性并显示了谷歌地图。它在IE 8上不起作用,在其他浏览器上也能正常工作,如果我不使用CSS,它在IE 上也能很好地工作
我的代码和一样
<div class="getDirectionsBtnMain">
<a href="#" id="new-yorkiframeNav" onclick="toggle_visibility('new-yorkiframe');">
</a>
</div>
<div id="new-yorkiframe" style="background: none repeat scroll 0% 0% rgb(5, 72, 65); width: 950px; border: 10px solid rgb(5, 72, 65);" class="tab-pane vcard">
<iframe frameborder="0" style="width: 100%; height: 379px;" marginheight="0" marginwidth="0"
src="https://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=+40+Wall+Street,+11th+Floor+New+York,+NY+10005&aq=&sll=37.0625,-95.677068&sspn=39.320439,86.572266&t=m&ie=UTF8&hq=&hnear=40+Wall+St,+New+York,+10005&iwloc=A&output=embed">
</iframe>
</div>
脚本为,
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
alert(e.style.display);
if (e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
if (e.style.display != 'block' && e.style.display != 'none')
e.style.display = 'block';
}
</script>
在CSS中,我使用这个属性,
#new-yorkiframe{display:none;}
首先,它没有显示其显示属性,它显示"null",我在脚本中提醒它在其他浏览器中的行为也一样,但在脚本中更改其属性后,它在除IE 之外的其他浏览器中显示地图
但如果我将其css属性更改为
new-yorkiframe{display:none;}
它的点击按钮在ie和其他浏览器上显示和隐藏地图。
我应该怎么做才能在第一次加载页面时隐藏地图??
希望与合作
提前感谢
在关闭html标记之前是否保留了"<script>..you code..</script>
"
试试这个:
<script type="text/javascript">
function toggle_visibility(id) {
var ele = document.getElementById(id);
if (ele.style.display == 'block')
ele.style.display = 'none';
else
ele.style.display = 'block';
}
window.onload = toggle_visibility('new-yorkiframe');
</script>