Switching an image using jQuery

后端 未结 7 1836
醉酒成梦
醉酒成梦 2021-02-01 23:29

Is there a better, more jQuery-ish way of handling this image substitution?

var image = $(obj).children(\"img\");
if ($(image).attr(\"src\") == \"Images/TreeColl         


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

    More jQueryish? Maybe! Clearer? I'm not sure!

    var image = $(obj).children("img");
    $(image).toggle(
      function () { $(image).attr("src", "Images/TreeExpand.gif");},
      function () { $(image).attr("src", "Images/TreeCollapse.gif");}
    );
    

提交回复
热议问题