我有这些代码:
<script type="text/javascript">
var screenWidth = window.screen.width;
var width_sides = (screenWidth - 980) / 2;
</script>
<div id="not_important" width=""></div>
我想将 div 的宽度设置为等于 javascript tagg 内方程的结果。我怎样才能做到这一点?
谢谢
最佳答案
<div id="not_important" width=""></div>
<script type="text/javascript">
var screenWidth = window.screen.width;
var width_sides = (screenWidth - 980) / 2;
document.getElementById('not_important').style.width = width_sides;
</script>
关于javascript - 在 html 标签中使用 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21804750/