根据从下拉菜单中选择的选项更改页面上的图像时,我遇到了脚本问题。当我使用一个下拉菜单更改一个图像时,我可以使其正常工作。但我正在尝试扩展代码,以便可以从一个下拉菜单中替换两个图像,但我不确定我的代码到底出了什么问题。
<script>
window.onload=function()
{
bp='http://www.nessasneedles.co.uk/images/layout/shop/samples/fabric/', //base url of your images
imgnum=4, //Number of your images. This should match on your comboboxes options.
thumb1=document.getElementById('outer_example'), //id of your outer image that will be changing. The outer of the bag
thumb2=document.getElementById('lining_example'), //id of the image using in the if clause for second image
combobox1=document.getElementById('outer_option'), // id of your combobox. The select box for the outer design.
combobox1.onchange=function()
{
thumb1.src=bp+'img'+this.value+'.jpg';
if (this.value = "Cats") {
thumb2.src=bp+'img'+"Purple Gingham"+'.jpg';
} else {
thumb2.src=bp+'img'+"Pink"+'.jpg';
};
};
}
</script>
1条答案
按热度按时间a64a0gku1#
在if语句中需要一个double ==:
Single =用于赋值,double ==用于比较。