jquery toggle with buttons two images?

五迷三道 提交于 2019-12-22 01:31:28

问题


To toggle hide/show, i used this code;

togglebtn.click(function() {
    var that = this;
    $('.togglecontainer').toggle(500, function(){
        var txt = $(that).html();
        $(that).html((txt == 'Show less') ? 'Show more' : 'Show less');
    });
});
togglebtn.trigger("click");

But it toggles text inside one button. I want two buttons, with two diffrent img src's let's say images/show.png and images/hide.png

Thanks in advance


回答1:


Have a look at this Tutorial - jQuery Image Swap Using Click - This may be what you are trying to achieve. Let us know how you get on.




回答2:


I'm not really sure this is wat you mean but: You could use the Id's of the buttons

togglebtn.click(function(){
            var btn = this;
        $('.togglecontainer').toggle(500, function(){
            var txt = $(btn).html();
            $(btn).html((txt == 'Show less') ? 'Show more' : 'Show less');
            $("#btn2_Id").html((txt == 'Show less') ? '<img src="http://yourdomain.com/images/hide.png"/>' : '<img src="http://yourdomain.com/images/show.png"/>');
        });
});


来源:https://stackoverflow.com/questions/4705454/jquery-toggle-with-buttons-two-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!