Switching an image using jQuery

后端 未结 7 1832
醉酒成梦
醉酒成梦 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:14

    Why set a variable when it isn't needed?

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

提交回复
热议问题