所以我正在嘗試創建一個用於更改圖像大小的選擇菜單,但我不知道這段代碼有什麼問題或者如何解決此問題。用Javascript更改HTML圖像大小
HTML:
<img id="dogpicture" src="dog1.png" alt="dog" height="150" width="150"></img>
<select id="dogsize" name="sizeofdog" onchange="dogsize(this.value);">
<option value="small"> small </option>
<option value="default" selected> default </option>
<option value="big"> big </option>
</select>
JS:
function dogsize(option){
if (option == "small"){
document.getElementById('dogpicture').height = "50";
document.getElementById('dogpicture').width = "50";
}
if (option == "default"){
document.getElementById('dogpicture').height = "100";
document.getElementById('dogpicture').width = "100";
}
if (option == "big"){
document.getElementById('dogpicture').height = "150";
document.getElementById('dogpicture').width = "150";
}
}
你怎麼知道這是錯的? – usr2564301
他們應該是數字。不值。刪除''''或者在末尾添加'px',如果你要發送字符串 –
@RadLexus,因爲它根本不起作用 – Arszenik