javascript - 如何翻译 style.fontSize = html5 文档的值?

标签 javascript html css

在下面的代码中,如果您删除文档类型,脚本不会执行它所执行的操作(即,它不会增加文本大小)。 如何转换 fontSize 做作来修复它?

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, height=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" />
        <style>
            #hello {
                font-family: "AvenirNextCondensed-Bold";
                font-size: 12pt;
            }
        </style>
    </header>
    <body>

        <div id="hello">
            Hello
        </div>
        <script>
        document.getElementById("hello").style.fontSize = 50;
        </script>
    </body>
</html>

最佳答案

要保留 !doctype,您可以将 js 更改为:

document.getElementById("hello").style.fontSize = "50px";

:)

关于javascript - 如何翻译 style.fontSize = html5 文档的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21923117/

相关文章:

html - 将响应式 css 菜单对齐到中间而不改变它的移动分辨率

javascript - 为 :checked 之前的所有元素设置样式

javascript - 如何动态设置快速服务器的端口?

javascript - 从 IBM Mobilefirst http 适配器调用后端 POST Web 服务时出错

javascript - 在react hook中获取没有正确的数据

html - 使 CSS Hover 状态保持在 "unhovering"之后

javascript - 如何在 CSS 和 Javascript 中为网格区域设置动画?

html - 之后在css中获取文本内容

javascript - 对一些常见元素进行模态重构

javascript - 如何将 jquery 函数作为文本传递,以便将其呈现为 html 并由其他脚本使用?