javascript - 在 html 标签中使用 javascript

标签 javascript html

我有这些代码:

<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/

相关文章:

javascript - Passport 自定义回调如何工作?

javascript - 如何用函数链中的空字符串替换数据库中的空值

javascript - Array.method 和 [].method 的区别

javascript - JavaScript 中的倒数计时器

html - Webpack:加载 *.eot 字体时出现 "OTS parsing error: invalid version tag"

javascript - 如何在js中处理一个非常大的数组

javascript - 在javascript中访问对象与变量的属性

html - Firefox 忽略输入类型 ="image"的宽度和高度

html - 从 MVC 中的 lambda 渲染 Html

html - CSS :first-child selector works如何