gpt4 book ai didi

javascript - document.getElementById 在 asp.net 中的
上失败

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:45 24 4
gpt4 key购买 nike

我有以下脚本来设置 heightdiv 上包含 Google map 控件:

<script>
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
//alert("Height:" + height)
document.getElementById('divMap').setAttribute("style", "width:" + height);
</script>

再往下,div定义:

    <div id="divMap" class="col-md-6" style="min-height: 800px; height:100%">
<map:GoogleMap ID="GoogleMap1" runat="server" Width="100%" Height="100%">
</map:GoogleMap>

<map:GoogleMarkers ID="GoogleMarkers1" TargetControlID="GoogleMap1" runat="server" OnClick="GoogleMarkers1_Click" />
</div>

该脚本在加载时运行良好。我得到 height浏览器窗口。

然而,getElementById()总是失败。

就像div脚本运行时不存在。如果我选择调试页面,无非就是<script>显示标签。

debuging script

我错过了什么,但是什么?

或者有另一种方法来设置 heightdiv在 asp.net 中?

最佳答案

我认为问题是您试图在 div 进入 DOM 之前访问它。试试这个:

<html>
<head>
</head>
<body>
<div id="divMap" class="col-md-6" style="min-height: 800px; height:100%">
<map:GoogleMap ID="GoogleMap1" runat="server" Width="100%" Height="100%">
</map:GoogleMap>
<map:GoogleMarkers ID="GoogleMarkers1" TargetControlID="GoogleMap1" runat="server" OnClick="GoogleMarkers1_Click" />
</div>

<script>
(function() {
/var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
//alert("Height:" + height)
document.getElementById('divMap').setAttribute("style", "width:" + height);

})();
</script>
</body>
</html>

关于javascript - document.getElementById 在 asp.net 中的 <div> 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52327971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com