Jquery套餐切换功能

效果图:

html+css+ jquery

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Jquery套餐切换功能</title>
		<style type="text/css">
			.taocan-box {
				display: flex;
				margin-top: 10px;
			}
			
			.taocan-box label {
				font-size: 14px;
				color: #666;
				margin-right: 10px;
			}
			
			.taocan-box div {
				flex: 1;
			}
			
			.price-ul li {
				float: left;
				padding: 0 14px;
				border: 1px solid #999;
				height: 26px;
				line-height: 26px;
				border-radius: 2px;
				background: none;
				margin-right: 12px;
				cursor: pointer;
				color: #666;
				list-style: none;
			}
			
			.price-ul li:hover {
				border-color: #00BDFF;
				color: #00BDFF
			}
			
			.price-ul .active {
				border: 1px solid #00BDFF;
				color: #00BDFF;
				background: url("img/select.png") right -1px bottom 0 no-repeat
			}
			
			.red {
				color: red;
			}
			
			.clearfix {
				zoom: 1;
				clear: both;
			}
			
			.clear:after,
			.clearfix:after {
				content: '';
				display: block;
				clear: both
			}
		</style>
	</head>

	<body>
		<div class="taocan-box">
			<label>套餐</label>
			<div>
				<ul class="price-ul clearfix">
					<li class="active" data-price="30"><span>月</span></li>
					<li data-price="80"><span>季</span></li>
					<li data-price="300"><span>年</span></li>
				</ul>
			</div>
		</div>
		<div class="taocan-box">
			<label>价格</label>
			<div>
				<b class="red" id="price"></b>
			</div>
		</div>
		<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
		<script type="text/javascript">
			$(function() {
				$('.price-ul li').each(function(index) {
					var price = $(this).attr('data-price');
					if(index == 0) {
						$('#price').html('¥' + Number(price).toFixed(2));
					}

					$(this).click(function() {
						$('.price-ul li').removeClass('active');
						$(this).addClass('active');
						$('#price').html('¥' + Number(price).toFixed(2));
					});
				});
				$('.price-ul li:first').click();
			});
		</script>
	</body>

</html>

用到的select.png图标(右键下载)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值