【问题标题】:HTML5 allow user to select font typeHTML5 允许用户选择字体类型
【发布时间】:2013-08-08 15:31:53
【问题描述】:

对于我的 JS html5 类,我正在尝试创建一个网页,允许用户选择背景颜色以及是否要使用 SANS SERIF 或 SANS 字体。我有背景颜色工作 -

var inputColor = prompt( "Enter a color name for the " +
    "background of this page", "" );
document.body.setAttribute( "style", "background-color: " + inputColor );

我不知道如何使用相同的想法并让他们在不擦除新背景颜色的情况下选择字体。

非常感谢您的建议。

【问题讨论】:

  • 我会将背景颜色和输入颜色存储到变量中,然后使用 setAttribute 同时设置它们。

标签: javascript css html fonts styles


【解决方案1】:

不要触摸style 属性,而是更改element.style.* 属性。

document.body.style.backgroundColor = "foo";
document.body.style.fontFamily = "bar";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-28
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2016-12-10
    • 2022-01-03
    • 2017-02-25
    相关资源
    最近更新 更多