Image widthプロパティ

Image 对象参考手册Image オブジェクト

定義と使い方

width プロパティは、画像の width 属性の値を設定または返します。

width プロパティは、画像の幅を指定します。

構文

imageObject.width=pixels


ブラウザサポート

Internet ExplorerFirefoxOperaGoogle ChromeSafari

すべての主要ブラウザは width プロパティをサポートしています。


例

例

画像の高さと幅を変更:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル チュートリアル(example.com)</title>
<script>
function changeSize(){
    document.getElementById("compman").height="250";
    document.getElementById("compman").width="300";
}
</script>
</head>
<body>

<img id="compman" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="画像サイズを変更">

</body>
</html>

試してみる »


Image 对象参考手册Image オブジェクトその他の拡張