JS/jQuery(隐藏div,在单击时显示div) [英] JS/jQuery (Hide div, show div on click)

查看:107
本文介绍了JS/jQuery(隐藏div,在单击时显示div)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个按钮.

我要显示两个divs.

I have two divs I want to show.

每个div都有不同的内容.

Each divs have different content.

我希望两个div只在页面上占用相同的空间.

I want both divs to only take up the same amount of space on the page.

我希望页面加载时如此显示div1,如果他们单击链接div2,则div1消失并且div2出现在其位置.

I want it so on page load, div1 is shown, and if they click link div2, div1 disappears and div2 appears in its place.

执行此操作的最佳方法是什么?以及如何?

What is the best way to go about doing this? and how?

推荐答案

除了所有最初的CSS和onload内容之外,您正在使用jquery, 我认为您正在寻找类似的东西

All the initial CSS and onload stuff aside and you're using jquery, I think you're looking for something like

$("#button2").click(function(){
    $("#div1").hide();
    $("#div2").show();
})

这篇关于JS/jQuery(隐藏div,在单击时显示div)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆