gpt4 book ai didi

javascript - 如果宽度较大,则更改背景颜色

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

如果宽度大于 100,我想更改背景颜色。

这是我的代码,但它不起作用。

感谢您的帮助!

<html>
<head>
<style type="text/css">
div#mydiv {
width: 200px;
height: 100px;
background-color: red;
}
</style>
<script language="JavaScript">
function () {
var mydiv = document.getElementById("mydiv");
var curr_width = parseInt(mydiv.style.width);
if (curr_width > 100) {
mydiv.style.BackgroundColor = "blue";
}
}

</script>
</head>
<body>

<div id="mydiv" style=""></div>

</body>
</html>

最佳答案

改变

parseInt(mydiv.style.width);
mydiv.style.BackgroundColor = "blue";

mydiv.offsetWidth
mydiv.style.backgroundColor = "blue";

关于javascript - 如果宽度较大,则更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26232954/

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