js实现点击标题,内容在同一窗口显示(隐藏与显示)

js实现点击标题,内容在同一窗口显示(隐藏与显示)

整体代码如下 :

<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title>xiaoliuliu</title>
		<link rel="stylesheet" href="css/xiaoliu.css">
	</head>

	<body>

		<header class="head bg-orange">
			
			<nav class="center-width">
				<a href="#" class="nav-picture active">图片</a>
				<a href="#" class="nav-article">文章</a>
			</nav>
			
		</header>

		<div class="body center-width">

			<section class="image">

				姓名:<input type="text" name="" id="" value="" />

			</section>

			<section class="article">

				<p>我叫111,你知道了吗?</p>
				<span id="shuoming">
					显然,这个只是实现了点击时,内容在同一画面进行切换,原理就是隐藏与显示。而并没有实现点击同一个
				</span>
			</section>
			
		</div>

		<script src="js/jquery-2.1.4.min.js"></script>
		<script>
			$('.head .center-width a').click(function() {
				var this_ = $(this);
				if(!this_.hasClass('active')) {
					$('.head .center-width .active').removeClass('active');
					this_.addClass('active');
					if(this_.hasClass('nav-picture')) {
						$('.body .article').hide();
						$('.body .image').show();
					} else {
						$('.body .image').hide();
						$('.body .article').show();
					}
				}
			})
		</script>
	</body>

</html>

注意:由于js代码与html中个别id已相互对应,如要修改,对应的js代码也要修改,否则不会有效果,在这个标准框架内,可自行添加内容

css代码如下:


* {
padding: 0;
margin: 0;
}
body {
background-color: #f9eee6;
padding: 0;
margin: 0;
font-size: 15px;
min-width: 840px;
}
.center-width {
display: block;
width: 840px ;
margin: 0 auto;
min-width: 840px ;
}
@media (min-width: 1400px) {
.center-width {
width: 1200px;
}
}
.bg-orange{
background-color: #ffa366;
color: #fff;
    }
.head{
height: 54px ;
line-height: 54px;
    }
.body {
background-color: #fefefe; 
min-height: 500px;
    }
.footer {
line-height: 34px;
font-size: 13px;
text-align: center;
}

/*页眉部分*/
    .head > nav a {
        display: inline-block;
        height: 100%;
        padding: 0 10px;
        flex-shrink: 16px;
        color: #fefefe;
        text-decoration: none;
    }
    .head > nav a.active {
        background-color: #f9eee6;
        color: #666;
    }
    .head > nav a:hover {
        color: #444;
    }
    .head > nav a.active:hover {
        color: #ffa366;
    }

    /*图片模块*/
    img {
        width: 100%;
        height: auto;
    }
    
    /*文章模块*/
    .article {
        font-family: "cursive";
        display: none;
    }

    .article p {
        padding: 0 120px;
        letter-spacing: 1px;
        line-height: 24px;
        text-indent: 32px;
        margin-bottom: 16px;
    }

    

jquery-2.1.4.min.js资源下载:/*! jQuery v2.1.4 | © 2005, 2015 jQuery Foundation, Inc. | jquery.org/license */
1.可以自己去jQuery官网下载该版本
2.资源已上传…

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

高中不复,大学纷飞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值