![](/img/trans.png)
[英]How to fix “Cannot read property 'style' of null”-Error in Javascript?
[英]How do I fix Cannot read property 'style' of null in JavaScript?
所以我的 function 根據 document.load 設置值更新進度條。 據我所見,它無法渲染該元素。 經過廣泛的研究,我不確定為什么我的其他 div 可以在 JS 中被識別和操作,但不是這個特定元素;
<div id="ProgressBar">
<div id="Percentage" class="innerBar" runat="server"></div>
</div>
<script type="text/javascript">
$(document).ready(function () {
SpaceLeftVar = 32;
UpdateProgress();
});
function UpdateProgress() {
const progressBarPercentage = document.getElementById('Percentage');
const transitionProgressBar = (progress) => {
setTimeout(() => {
progressBarPercentage.style.width = progress + '%';
}, 200);
}
}
</script>
setTimeout(() => {
progressBarPercentage && (progressBarPercentage.style.width = progress + '%')
}, 200);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.