老师你好 请求帮助 在选择版本和颜色出错 选择第二个的时候默认选项颜色不恢复原来的颜色
问题描述
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="static/css/detail.css" />
<link rel="stylesheet" href="static/css/layui.css" />
<link rel="stylesheet" href="static/css/style.css" />
<link rel="stylesheet" type="text/css" href="static/font-awesome/css/font-awesome.min.css">
<script type="text/javascript" src="static/js/layui.all.js" ></script>
<script type="text/javascript" src="static/js/jquery-3.3.1.min.js" ></script>
<script type="text/javascript" src="static/js/detail.js" ></script>
<title>红米6A立即购买—小米商城</title>
<style>
*{padding: 0;margin: 0;list-style: none;text-decoration: none;}
/*头*/
.header-lr{width:100%;height: 50px; box-shadow: 0px 10px 10px #ccc;margin-top: 10px;border-top: 2px solid #ccc;}
.header-lr-box{width: 1226px; height: 50px;margin:0 auto;}
.header-lefts li{width:70px;height: 50px;float: left;text-align: center;line-height: 50px;}
.header-lefts li a{color: #23262E;font-size: 14px;font-weight: none;}
.header-right{float: right;}
.header-right li{float: left; width: 70px;height: 50px;line-height: 50px;text-align: center;}
.header-right span{float: left;line-height: 50px; color: #aaa;font-size: 12px;}
.detail-img{width: 1226px;margin: 0 auto;}
.detail-img h6{font-size: 16px;font-weight: bold;margin: 10px auto;float: left;}
/*主要内容*/
.content-box{width: 1226px;margin: 30px auto;}
.content-box-left{width: 560px; height: 600px;float: left;}
.content-box-right{width: 600px;float: right;}
.content-box-right p{color: #aaa;margin: 10px auto;}
.content-box-map{width: 100%;height: 100px;background: /*rgba(51,51,51,0.2)*/#fafafa;margin: 20px auto;border: 1px solid #ccc;}
.content-box-map span{display: inline-block;margin-top: 10px;margin-left: 15px;}
.content-box-map i{position: relative;left: 12px;}
.content-box-money .rls{border: 1px solid #FF8200;}
.content-box-money div{width: 255px;height: 50px;text-align: center;float: left;border: 1px solid #ccc;line-height: 50px;padding: 0px 20px;}
.content-box-money span{float: right;color: #ccc;}
.content-box-money p{font-size: 18px;color: #333;margin: 15px 0px;}
.content-box-color p{font-size: 18px; color: #333; margin: 15px auto;}
.content-box-color div{width:255px ; height:50px ;float: left;padding:0px 20px;text-align: center;line-height: 50px;border:1px solid #ccc;}
.content-box-color span{display:inline-block;height: 16px;width: 16px;border-radius: 8px;margin-right: 10px;}
.content-bz-box0 p{float: left;font-size: 18px; color: #333;margin: 20px 0px;}
.content-bz-box0 a{float: right;font-size: 14px; margin: 20px 0px; color: #ff8200;}
.content-bz-box1{width: 598px;height: 150px;border: 1px solid #ccc;}
.content-bz-box1 span{float: left;width: 10px;height: 10px;line-height: 10px;border-radius: 6px;display: inline-block;margin: 60px auto;margin-left: 40px;}
.content-bz-box1 img{float: left;margin: 50px 20px;}
.content-bz-p{margin: 40px auto;}
.content-bz-p p{margin: 10px auto;}
.content-bz-p span{float: right;margin: 0px;margin-right:20px; color: #ccc;width: 50px;}
.content-bz-btn{color:rgba(0,0,0,0);border: 1px solid #ccc;}
.content-zs{width: 100%; height: 130px;background: #f9f9f9;margin-top: 30px;}
.content-zs div{margin: 0px 30px 20px;height: 50px; line-height: 30px; }
.content-zs p {float: left;}
.content-zs span{float: right;line-height: 50px;}
.content-box-color .rls{border: 1px solid #FF8200;}
.content-box-money,.content-box-color{width: 600px;}
.shop-che{width: 240px;height: 50px;text-align: center;line-height: 50px;background: #FF5722;color: #FFF; }
</style>
</head>
<body>
<div class="header">
<div class="menu">
<ul class="menu-left">
<li>
<a href="#">小米商城</a><span>|</span></li>
<li>
<a href="#">MIUI</a><span>|</span></li>
<li>
<a href="#">IOT</a><span>|</span></li>
<li>
<a href="#">云服务</a><span>|</span></li>
<li>
<a href="#">小爱分享平台</a><span>|</span></li>
<li>
<a href="#">金融</a><span>|</span></li>
<li>
<a href="#">有品</a><span>|</span></li>
<li>
<a href="#">企业服务</a><span>|</span></li>
<li>
<a href="#">SelectRegion</a>
</li>
</ul>
<div class="menu-right">
<ul>
<li>
<a href="#">登录</a><span>|</span></li>
<li>
<a href="#">注册</a><span>|</span></li>
<li>
<a href="#">我的订单</a>
</li>
<li class="menu-rshop">
<a><i class="fa fa-shopping-cart"> 购物车(0)</i></a>
<div>购物车中还没有商品,赶紧选购吧!</div>
</li>
</ul>
</div>
</div>
</div>
<div class="contents" style="background: #F6F6F6;;">
<div class="content">
<div class="contentMenu">
<div class="contentMenu-imgbox">
<img src="static/images/footlogo.png" style="margin: 3px 5px;margin-right: 10px;" />
<img src="static/images/logoAD.gif" />
</div>
<!--下拉新品N-->
<ul class="contentMenu-ul">
<li>小米手机
<div class="mi-box">
<div class="mi-boxdiv">
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
</div>
</div>
</li>
<li>红米
<div class="mi-box">
<div class="mi-boxdiv">
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
</div>
</div>
</li>
<li>电视</li>
<li>笔记本</li>
<li>盒子</li>
<li>新品</li>
<li>路由器
<div class="mi-box">
<div class="mi-boxdiv">
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
<div class="mi-box1">
<div class="mi-new">新品</div>
<div class="mi-shop">
<img src="static/images/phone/phone1.png" />
<br />
<a href="#">小米2s</a>
<br />
<a href="#" style=" color: #FF8200;">3299元</a>
</div>
</div>
<span></span>
</div>
</div>
</li>
<li>智能硬件</li>
<li>服务</li>
<li>社区</li>
</ul>
<div class="contentMenu-form">
<form action="">
<input type="text" />
<div class="contentMenu-intxt">
<a href="#">预热618</a>
<a href="#">小米电视</a>
</div>
<div class="sousou-btn"><i class="fa fa-search"></i></div>
</form>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<div class="header-lr">
<div class="header-lr-box">
<div class="header-lefts">
<ul>
<li>
<a>小米8</a>
</li>
<li>
<a>小米8se</a>
</li>
</ul>
</div>
<div class="header-right">
<ul>
<li>
<a>概述</a>
</li><span>|</span>
<li>
<a>图集</a>
</li><span>|</span>
<li>
<a>参数</a>
</li><span>|</span>
<li>
<a>F码通道</a>
</li><span>|</span>
<li>
<a>用户评价</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clear"></div>
<!--头部分结束-->
<div class="content-box">
<div class="content-box-left">
<div class="layui-carousel" id="test1">
<div carousel-item>
<div><img src="static/images/lun/1.jpg"></div>
<div><img src="static/images/lun/2.jpg"></div>
<div><img src="static/images/lun/3.jpg"></div>
<div><img src="static/images/lun/4.jpg"></div>
</div>
</div>
</div>
<div class="content-box-right">
<h1>红米6A</h1>
<p>12nm高性能处理器 / 5.45" 小巧全面屏 / 1300万高清相机 / “小杨柳腰”机身</p>
<h2 style="color: #FF8200;border-bottom: 1px solid #aaa;height: 30px;">599</h2>
<div class="content-box-map">
<i class="fa fa-map-marker"></i>
<span>北京 北京市 东城区 永定门外街道 <a href="#" style="color: #FF8200;">修改</a></span><br />
<span><a href="#" style="color: #FF8200;margin-left: 12px;">有现货</a></span>
</div>
<div class="content-box-money">
<p>选择版本</p>
<div class="detail_much_left" style="margin-right: 5px;">4G+64G 全网通<span data-val="599">599</span></div>
<div class="detail_much_left">6G+64G 全网通<span data-val="699">699</span></div>
</div>
<div class="clear"></div>
<div class="content-box-color">
<p>选择颜色</p>
<div class="content-color-left content-color-left-rls" style="margin-right: 5px;margin-bottom: 5px;"><span style="background:#F6E6D8; "></span>金色</div>
<div class="content-color-left"><span style="background:#3C3F43;"></span>深灰</div>
<div class="content-color-left" style="margin-right: 5px;"><span style="background:#D93239;"></span>亮红</div>
<div class="content-color-left"><span style="background:#3871B7;"></span>亮蓝</div>
</div>
<div class="clear"></div>
<div class="content-box-bz">
<div class="content-bz-box0">
<p>选择小米提供的保障服务</p>
<a href="#">了解保障条款</a>
<div class="clear"></div>
</div>
<div class="content-bz-box1">
<span class="fa fa-check-circle content-bz-btn"></span>
<img src="static/images/bz.jpg">
<div class="content-bz-p">
<p style="font-size: 18px; color: #000;">意外保障服务</p>
<p>手机意外摔落/进水/碾压等损坏</p>
<b class="fa fa-check-square content-bz-btn"></b> 我已阅读 <a href="#"> 服务条款 </a>|<a href="#"> 服务条款 </a>
<span data-val="99">99元</span>
</div>
</div>
</div>
<!--2-->
<div class="clear"></div>
<div class="content-box-bz">
<div class="content-bz-box1">
<span class="fa fa-check-circle content-bz-btn"></span>
<img src="static/images/bz.jpg">
<div class="content-bz-p">
<p style="font-size: 18px; color: #000;">碎屏保障服务</p>
<p>手机意外碎屏</p>
<b class="fa fa-check-square content-bz-btn"></b> 我已阅读 <a href="#"> 服务条款 </a>|<a href="#"> 服务条款 </a>
<span data-val="179">179元</span>
</div>
</div>
</div>
<div class="clear"></div>
<div class="content-zs">
<div><p>小米8 6GB+64GB 黑色</p><span id="mi-jg">699元</span></div>
<p id="tojg" style="color:#FF6A00;font-size: 25px;margin-left: 30px;">总计 : 699元</p>
</div>
<div class="shop-che">加入购物车</div>
<p><i class="fa fa-check-circle-o"></i> 7天无理由退货 <i class="fa fa-check-circle-o"></i> 15天质量问题换货 <i class="fa fa-check-circle-o"></i> 365天保修</p>
</div>
</div>
<div class="clear"></div>
<!--说明-->
<div class="detail-img">
<h6>特别说明</h6>
<img src="static/images/sm.jpg" />
<h6>官方微信</h6>
<img src="static/images/2.jpg" />
</div>
<!--尾-->
<div class="footers">
<div class="footer">
<div class="for-li">
<a href="#"><i class="fa fa-wrench"> 预约维修服务</i><span>|</span></a>
<a href="#"><i class="fa fa-rotate-right"> 7天无理由退货</i><span>|</span></a>
<a href="#"><i class="fa fa-refresh"> 15天免费换货</i><span>|</span></a>
<a href="#"><i class="fa fa-gift"> 满150元包邮</i><span>|</span></a>
<a href="#"><i class="fa fa-map-marker"> 520余家售后网点</i></a>
</div>
</div>
</div>
<div class="for-li-1">
<div class="for-li-a">
<dl>
<dt>帮助中心</dt>
<dd>
<a href="#">账户管理</a>
</dd>
<dd>
<a href="#">购物指南</a>
</dd>
<dd>
<a href="#">订单操作</a>
</dd>
</dl>
<dl>
<dt>服务支持</dt>
<dd>
<a href="#">售后政策</a>
</dd>
<dd>
<a href="#">自助服务</a>
</dd>
<dd>
<a href="#">相关下载</a>
</dd>
</dl>
<dl>
<dt>线下门店</dt>
<dd>
<a href="#">小米之家</a>
</dd>
<dd>
<a href="#">服务网点</a>
</dd>
<dd>
<a href="#">授权体验店</a>
</dd>
</dl>
<dl>
<dt>关于小米</dt>
<dd>
<a href="#">了解小米</a>
</dd>
<dd>
<a href="#">加入小米</a>
</dd>
<dd>
<a href="#">投资者关系</a>
</dd>
</dl>
<dl>
<dt>关注我们</dt>
<dd>
<a href="#">新浪微博</a>
</dd>
<dd>
<a href="#">官网微博</a>
</dd>
<dd>
<a href="#">联系我们</a>
</dd>
</dl>
<dl>
<dt>特色服务</dt>
<dd>
<a href="#">F码通道</a>
</dd>
<dd>
<a href="#">礼物码</a>
</dd>
<dd>
<a href="#">防伪查询</a>
</dd>
</dl>
<div class="for-conten">
<p class="suorg">Feir-520-1314</p>
<p class="suorg-1">周一至周日 8:00-18:00<br />(仅收市话费)</p>
<button class="btn"><span class="fa fa-commenting "></span> 联系客服</button>
</div>
</div>
</div>
<div class="clear"></div>
<div class="for-end">
<div class="end-1" style="margin-right: 15px;"><img src="static/images/footlogo.png" alt="" /></div>
<div class="end-2">
<div class="endli">
<ul>
<li>小米商城<span></span></li>
<li>MIUI<span></span></li>
<li>米家<span></span></li>
<li>米聊<span></span></li>
<li>多看<span></span></li>
<li>游戏<span></span></li>
<li>路由器<span></span></li>
<li>米粉卡<span></span></li>
<li>政企服务<span></span></li>
<li>小米天猫店<span></span></li>
<li>隐私政策<span></span></li>
<li>问题反馈<span></span></li>
<li>Select Region</li>
</ul>
</div>
<div class="endli-p">
<a href="#">©mi.com</a>
京ICP证110507号
<a href="#">京ICP备10046444号</a>
<a href="#">京公网安备11010802020134号</a>
<a href="#">京网文[2014]0059-0009号</a>
</a>
<br> 违法和不良信息举报电话:185-0130-1238,本网站所列数据,除特殊说明,所有数据均出自我司实验室测试
</div>
</div>
<div class="end-3">
<img src="static/images/footericon1.png" alt="" class="icon" style="margin-right: 10px;" />
<img src="static/images/footericon2.png" alt="" class="icon" style="margin-right: 10px;" />
<img src="static/images/footericon3.png" alt="" class="icon" style="margin-right: 10px;" />
<img src="static/images/footericon4.png" alt="" class="icon" style="margin-right: 10px;" />
<img src="static/images/footericon5.png" alt="" class="icon" />
</div>
<div class="font">探索黑科技,小米为发烧而生! </div>
</div>
</body>
<script>
layui.use('carousel', function(){
var carousel = layui.carousel;
//建造实例
carousel.render({
elem: '#test1'
,width: '560px' //设置容器宽度
,height:'600px'
,arrow: 'always' //始终显示箭头
//,anim: 'updown' //切换动画方式
});
});
</script>
<script>
//默认第一版本 替换class名方法
$(document).ready(function(){
//获取class eq遍历(0)从0开始(代表第一个)替换class名 为.content-box-bb rls
$(".detail_much_left").eq(0).attr("class",".detail_much_left rls")
$(".content-color-left").eq(0).attr("class",".content-color-left rls")
//点击选中的版本
$(".detail_much_left").click(function(){
$(".detail_much_left").attr("class",".detail_much_left")
$(this).attr("class",".detail_much_left rls")
})
//点击切换颜色
$(".content-color-left").click(function(){
$(".content-color-left").attr("class",".content-color-left")
$(this).attr("class",".content-color-left rls")
})
})
</script>
</html>
问题解答
回答1:你的写法问题,attr("class","class名前面不到带点号");这是个很小的细节哦,要注意
回答2:已解决
相关文章: