Style fontWeight 屬性

定義和用法
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 屬性的值從父元素繼承。 |
瀏覽器支持
所有主要瀏覽器都支持 fontWeight 屬性。
注意:IE7 及更早的版本不支持 "inherit" 值。IE8 只有規(guī)定了 !DOCTYPE 才支持 "inherit"。IE9 支持 "inherit"。
實例
實例
更改字體粗細:
<html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Change font weight</button>
</body>
</html>
<head>
<script>
function displayResult()
{
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">This is some text.</p>
<br>
<button type="button" onclick="displayResult()">Change font weight</button>
</body>
</html>
嘗試一下 ?

更多建議: