一键隐藏/显示图像

时间:2013-06-08 22:22:54

标签: javascript jquery html

你能帮我做这样的事吗(javascript,jquery ......)

http://m.uploadedit.com/b016/1370729652780.gif

Nn点击'1'显示'pic1'并隐藏'pic2',反之亦然

2 个答案:

答案 0 :(得分:2)

http://jsfiddle.net/qYCUJ/试试这个

<强> HTML

<button onclick="showhide_menu('btn1');">Show/Hide.  </button>

<button onclick="showhide_menu('btn2');">Show/Hide.  </button>

<div id="btn1" class="btn" style="display:none;">
<img src="http://healthystartups.com/storage/600px-MA_Route_1.png?__SQUARESPACE_CACHEVERSION=1319542839834"/>
</div>

<div id="btn2" class="btn" style="display:none;">
<img src="http://jenntgrace.com/wp-content/uploads/2012/12/2.png"/>
</div>

jQuery JS

window.showhide_menu = function(id){
$('.btn:not(#'+id+')').hide();
$("#" + id).toggle();
}

答案 1 :(得分:1)

要在一个按钮上调用两个函数,请设置按钮属性onclick="hideandshow()",然后在javascript文件或<script>标记中定义函数:

function hide(){
    ... //your code here
}
function show(){
    ... //your code here
}
function hideandshow(){
    hide();
    show();
    return true;
}
相关问题