HTML DOM width 屬性
定義和用法
width 屬性設(shè)置元素的寬度。
語(yǔ)法:
Object.style.width=auto|length|%
可能的值
值 | 描述 |
---|---|
auto | 默認(rèn)。瀏覽器可計(jì)算出實(shí)際的寬度。 |
% | 定義基于其包含塊的百分比寬度。 |
length | 使用 px、cm 等單位定義寬度。 |
實(shí)例
本例設(shè)置按鈕的寬度:
<html>
<head>
<script type="text/javascript">
function setWidth()
{
document.getElementById("b1").style.width="300px";
}
</script>
</head>
<body>
<input type="button" id="b1" onclick="setWidth()"
value="Change width to 300 px" />
</body>
</html>