【发布时间】:2017-04-19 07:03:03
【问题描述】:
所以我正在尝试创建一个选择菜单来更改图像的大小,但我不知道这段代码有什么问题或如何修复它。
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";
}
}
【问题讨论】:
-
你怎么知道错了?
-
它们应该是数字。不是价值观。删除
"。或者如果您要作为字符串发送,请在末尾添加px。 -
@RadLexus 因为它根本不起作用
-
您本可以在您的问题中提到这一点。不要使用确切的短语“它根本不起作用”——要明确地说“什么都没有发生,没有错误,屏幕上没有变化”。
标签: javascript html image styling