Style fontWeight 屬性

Style 對象參考手冊 Style 對象

定義和用法

fontWeight 屬性設置或返回字體的粗細。

語法

設置 fontWeight 屬性:

Object.style.fontWeight="value"

返回 fontWeight 屬性:

Object.style.fontWeight

描述
normal 默認。字體是 normal(正常的)。
lighter 定義更細的字體。
bold 定義粗體。
bolder 定義更粗的字體。
100
200
300
400
500
600
700
800
900
定義由細到粗的字元。400 等同於 normal,700 等同於 bold。
inherit fontWeight 屬性的值從父元素繼承。


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要流覽器都支持 fontWeight 屬性。

注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。


實例

實例

更改字體粗細:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function displayResult(){
    document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>

<p id="p1">這是一些文本。</p>
<br>
<button type="button" onclick="displayResult()">修改字體粗細</button>

</body>
</html>



Style 對象參考手冊 Style 對象