-1

我在使用从下拉菜单中选择的选项更改页面上的图像的脚本时遇到问题。当我有一个下拉菜单更改一张图像时,我可以让它工作。但我正在尝试扩展我的代码,以便我可以从一个下拉菜单中替换两个图像,我不确定我的代码有什么问题。

<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';
        };    
    };

}

4

1 回答 1

1

您的 if 语句中需要一个 double == :

if (this.value == "Cats") {

Single = 用于赋值,double == 用于比较。

于 2012-04-15T15:00:38.153 回答