tab栏的制作

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}

			.box {
				width: 980px;
				margin: 50px auto;
				
				
			}
			
			.tab {
				border-bottom: 1px solid #e4393c;
				border-top: 1px solid #eeeeee;
				background-color: #f7f7f7;
			}

			.item {
				display: none;
			}

			 li {
				display: inline-block;
				padding: 10px 25px;
				color: #666;
				font: 14px/150% tahoma,arial,Microsoft YaHei,Hiragino Sans GB,"\u5b8b\u4f53",sans-serif;
				cursor: pointer;
			}

			.current {
				background-color: #e4393c;
				color: #fff;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<div class="tab">
				<ul>
					<li class="current">商品介绍</li>
					<li>规格包装</li>
					<li>售后保障</li>
					<li>商品评价(10万+)</li>
					<li>手机社区</li>
				</ul>
			</div>
			<div class="tips">
				<div class="item" style="display: block;">商品介绍模块内容</div>
				<div class="item">规格包装模块内容</div>
				<div class="item">售后保障模块内容</div>
				<div class="item">商品评价模块内容</div>
				<div class="item">手机社区模块内容</div>
			</div>
		</div>
		<script type="text/javascript">
			var items = document.querySelectorAll('.item');
			var lis = document.querySelectorAll('.tab li');
			
			for (var i = 0; i < lis.length; i++) {
            //这里两次用到排它思想,第一次用点击不同的tab时样式发生变化,第二次用在对相应的内容的display属性进行的不同的赋值,达到显示与不显示的差异。
				 lis[i].setAttribute('index',i);
				lis[i].onclick = function() {
//第一次
					for (j = 0; j < lis.length; j++) {
						lis[j].className = '';
					}
					this.className = 'current';
					var index = this.getAttribute('index');
					for (j = 0; j < lis.length; j++) {
//第二次
						items[j].style.display = 'none';
					}
					items[index].style.display = 'block';
				}
				
			}
		</script>
	</body>
</html>

使用到了自定义属性index,以此来将li与对应的div联系起来。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Flutter 底部导航可以使用 `BottomNavigationBar` 组件来实现。 首先,需要在 `StatefulWidget` 的 `build` 方法中创建 `BottomNavigationBar` 组件并设置它的 `items` 属性,该属性接受一个包含每个导航项的 `BottomNavigationBarItem` 对象的列表。 例如: ```dart class MyBottomNavigationBar extends StatefulWidget { @override _MyBottomNavigationBarState createState() => _MyBottomNavigationBarState(); } class _MyBottomNavigationBarState extends State<MyBottomNavigationBar> { int _currentIndex = 0; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('My Bottom Navigation Bar'), ), body: Container( child: Center( child: Text('This is the $_currentIndex tab'), ), ), bottomNavigationBar: BottomNavigationBar( currentIndex: _currentIndex, onTap: (int index) { setState(() { _currentIndex = index; }); }, items: [ BottomNavigationBarItem( icon: Icon(Icons.home), label: 'Home', ), BottomNavigationBarItem( icon: Icon(Icons.search), label: 'Search', ), BottomNavigationBarItem( icon: Icon(Icons.person), label: 'Profile', ), ], ), ); } } ``` 在这个例子中,我们创建了一个 `_currentIndex` 变量来存储当前选中的导航项的索引。在 `build` 方法中,我们创建了一个包含三个导航项的 `BottomNavigationBar` 组件,并将其传递给 `bottomNavigationBar` 属性。每个导航项都由一个 `BottomNavigationBarItem` 对象表示,它包含一个图标和一个标签。 我们还为 `BottomNavigationBar` 组件设置了 `currentIndex` 属性,以确定当前选中的导航项。当用户点击某个导航项时,我们使用 `onTap` 回调函数来更新 `_currentIndex` 变量,并调用 `setState` 方法来重建界面。 最后,我们将 `BottomNavigationBar` 组件放在 `Scaffold` 组件的 `bottomNavigationBar` 属性中,并将其他内容放在 `Scaffold` 组件的 `body` 属性中。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

hcoke

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

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

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

打赏作者

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

抵扣说明:

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

余额充值