gpt4 book ai didi

javascript - 在javascript中获取样式

转载 作者:太空宇宙 更新时间:2023-11-04 04:44:54 25 4
gpt4 key购买 nike

当 div 的大小为 50% 到 100% 时,我正在尝试调整 div 的大小。但是,当我尝试 console.log div 的当前大小时,它只记录空白...有什么问题吗?

window.onload = function() {
//declare vars
var fullbox = document.getElementById('box'),
minBut = document.getElementById('down');

minBut.onclick = function() {
if(fullbox.style.width == "50%") {
fullbox.style.width = "100%";
} else {
fullbox.style.width = "50%";
}
}
}

最佳答案

如果之前未为该元素初始化宽度,则可能会出现这种情况。第二次应该是50%。

通过添加 alert(fullbox.style.width); 进行测试

FIDDLE

关于javascript - 在javascript中获取样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14703652/

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