jQuery图像交换if-else语句不起作用

Car*_*nio 2 html javascript jquery if-statement function

我有一个jQuery的问题.

我有以下代码在里面 $(document).ready(function() {...})

 $("#one_div").hide();

 $('#button').click(function(){
        if (this.src == 'img/img1.png'){        
            this.src = 'img/img2.png';
        } 
        else {
            this.src = 'img/img1.png';
        }
        $("#one_div").slideToggle(800);
    });
Run Code Online (Sandbox Code Playgroud)

#button是图像的ID.one_div是div的ID.

实际上,单击图像会切换div,但问题是图像只交换一次,img1从而img2换回,并且从不切换回来.我做了什么我做错了?

tym*_*eJV 5

你忘了你的第二个 =

(this.src == 'img/img1.png'){   
Run Code Online (Sandbox Code Playgroud)