【发布时间】:2023-03-12 22:51:01
【问题描述】:
如何使用 javascript 更改 #win img 样式?我想将样式更改为:max-width: 40%; max-height: 40%; 使用 javascript 或 jQuery。
#win img {
max-width: 100%;
max-height: 100%;
width: auto;
height: auto;
}
<div id="win" align="center" style="width: auto; margin-top: 30px; height: auto; max-width: 80%; max-height: 80%; overflow: auto;"></div>
<script type="text/javascript">
document.getElementById("win").style["img"] = 'max-width: 40%; max-height: 40%;';
</script>
【问题讨论】:
-
不能直接改CSS或者HTML吗?使用 JS 进行样式设置不是一个好主意。
标签: javascript jquery html css