小编Car*_*nio的帖子

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

我有一个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换回,并且从不切换回来.我做了什么我做错了?

html javascript jquery if-statement function

2
推荐指数
1
解决办法
866
查看次数

标签 统计

function ×1

html ×1

if-statement ×1

javascript ×1

jquery ×1