如何在onClick上切换两个图像 [英] How to toggle two images onClick
本文介绍了如何在onClick上切换两个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作可折叠的treeView.
我已经做好了一切,只要按一下+
和-
图标就可以切换它们.
I'm making a collapsible treeView.
I made it all, I just need my +
and -
icons to toggle whenever they are clicked.
当我使用jQuery和以下代码将图标从+
更改为-
时,就完成了工作:
I did the part when I change an icon from +
to -
, on click, with jQuery with the following code:
$(this).attr('src','../images/expand.gif');
问题是,当我再次单击该节点时,我不知道如何使它反过来:)
Problem is, I don't know how to make it go other way around, when i click on the node again :)
推荐答案
这应该有效:
<style>
.expand{
content:url("http://site.com/expand.gif");
}
.collapse{
content:url("http://site.com/collapse.gif");
}
</style>
<img class="expand">
<script>
//onclick code
$('img.expand').toggleClass('collapse');
</script>
这篇关于如何在onClick上切换两个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文