HTML DOM Style fontStyle 属性
htmlweb developmentfront end technology更新于 2024/3/15 0:12:17
HTML DOM Style fontStyle 属性用于设置或返回文本的字体样式。它用于指定元素文本的正常、斜体或倾斜样式。
以下是语法 −
设置 fontStyle 属性 −
object.style.fontStyle = "normal|italic|oblique|initial|inherit"
让我们看一个关于 fontStyle 属性的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
#demo2,#demo1 {
font-family: 'times new roman';
font-size: 25px;
}
</style>
<script>
function changeFontStyle() {
document.getElementById("demo1").style.fontStyle="italic";
document.getElementById("demo2").style.fontStyle="italic";
document.getElementById("Sample").innerHTML="The font style has been changed for the above paragraphs.";
}
</script>
</head>
<body>
<div id="demo1" >This is demo text 1</div>
<div id="demo2">This is demo text 2</div>
<p>Change the above divs font style by clicking the below button</p>
<button onclick="changeFontStyle()">Change fontStyle </button>
<p id="Sample"></p>
</body>
</html>
输出

点击"更改字体样式"按钮 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

