hide/show a image in jquery

前端 未结 7 1442
逝去的感伤
逝去的感伤 2021-02-14 16:57

How to show/hide the image on clicking the hyperlink?



        
7条回答
  •  离开以前
    2021-02-14 17:48

    I had to do something like this just now. I ended up doing:

    function newWaitImg(id) {
        var img = {
           "id" : id,
           "state" : "on",
           "hide" : function () {
               $(this.id).hide();
               this.state = "off";
           },
           "show" : function () {
               $(this.id).show();
               this.state = "on";
           },
           "toggle" : function () {
               if (this.state == "on") {
                   this.hide();
               } else {
                   this.show();
               }
           }
        };
    };
    
    .
    .
    .
    
    var waitImg = newWaitImg("#myImg");
    .
    .
    .
    waitImg.hide(); / waitImg.show(); / waitImg.toggle();
    

提交回复
热议问题