对于我的 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 );
我不知道如何使用相同的想法让他们在不删除新背景颜色的情况下选择字体。
非常感谢您的建议。
最佳答案
不要修改 style
属性,而是更改 element.style.*
属性。
document.body.style.backgroundColor = "foo";
document.body.style.fontFamily = "bar";
关于javascript - HTML5 允许用户选择字体类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18130128/