样式效果如下,点击商品详情 添加样式active

代码

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<style>
.P_nav {
top: 0;
position: absolute;
width: 888px;
height: 48px;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
}
.P_nav .active {
color: #d41c44;
background-color: #fff;
font-weight: bold;
}
.P_nav .active i {
position: absolute;
height: 45px;
line-height: 0;
width: 100%;
top: -1px;
left: 0;
border-top: 4px solid #d41c44;
border-bottom: 1px solid #fff;
}
.P_nav span {
position: relative;
display: inline-block;
border-right: 1px solid #eaeaea;
width: 159px;
color: #333;
text-align: center;
height: 48px;
line-height: 48px;
font-size: 16px;
cursor: pointer;
vertical-align: top;
}
a, a:hover {
color: #51b8f1;
}
.goods_parameter {
padding: 15px 0 0 20px;
overflow: hidden;
*zoom: 1;
position: relative;
border-left: 1px solid #eaeaea;
border-right: 1px solid #eaeaea;
border-bottom: 1px solid #eaeaea;
}
ol, ul {
list-style: none;
}
.goods_parameter li {
float: left;
width: 40%;
height: 18px;
line-height: 18px;
font-size: 12px;
color: #333;
padding: 5px 0 0 0;
margin-right: 3%;
}
.ellipsis {
overflow: hidden;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
white-space: nowrap;
word-break: keep-all;
word-wrap: normal;
}
.P_nav span em {
color: #d41c44;
font-style: normal;
}
</style>
 
</head>
<body>
<span>11111</span>
<div class="P_nav j-nav" style="">
<span id="s1" class="j-imagedetailTab j-navtab active" style="cursor:pointer" onclick="showProductInfo(1)">商品详情<i></i></span>
<span id="s2" class="j-userratingTab j-navtab" style="cursor:pointer" onclick="showProductInfo(2)">用户评价<em> <b id="commentCounts" class="commentCount v1 v0">2264</b> </em><i></i></span>
</div>
<div id="goodsDetail" class="j-imagedetail j-navinfo">
 
<ul class="goods_parameter">
<li title="5.8 英寸" class="ellipsis">屏幕尺寸:5.8 英寸</li>
<li title="1200万像素" class="ellipsis">后置摄像头像素:1200万像素</li>
<li title="A11+M11 运动协处理器" class="ellipsis">CPU型号:A11+M11 运动协处理器</li>
<li title="5.6英寸及以上" class="ellipsis">屏幕尺寸:5.6英寸及以上</li>
<li title="64GB" class="ellipsis">机身内存:64GB</li>
<li title="全网通" class="ellipsis">网络类型:全网通</li>
<li title="iPhone X" class="ellipsis">型号(宣传型号):iPhone X</li>
<li title="2017.09.22" class="ellipsis">上市时间:2017.09.22</li>
</ul>
</div>
<div id="userRating" class="goods_parameter">
<br />
<br />
212121323234
<br />
212121323234
</div>
<script>
function showProductInfo(a) {
if (a == 1) {
addClass(document.getElementById('s1'), 'active');
removeClass(document.getElementById('s2'), 'active');
document.getElementById('goodsDetail').style.display = "";
document.getElementById('userRating').style.display = "none";
}
else {
addClass(document.getElementById('s2'), 'active');
removeClass(document.getElementById('s1'), 'active');
document.getElementById('goodsDetail').style.display = "none";
document.getElementById('userRating').style.display = "";
}
}
function hasClass(ele, cls) {
cls = cls || '';
if (cls.replace(/\s/g, '').length == 0) return false; //当cls没有参数时,返回false
return new RegExp(' ' + cls + ' ').test(' ' + ele.className + ' ');
}
function addClass(ele, cls) {
if (!hasClass(ele, cls)) {
ele.className = ele.className == '' ? cls : ele.className + ' ' + cls;
}
}
function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
var newClass = ' ' + ele.className.replace(/[\t\r\n]/g, '') + ' ';
while (newClass.indexOf(' ' + cls + ' ') >= 0) {
newClass = newClass.replace(' ' + cls + ' ', ' ');
}
ele.className = newClass.replace(/^\s+|\s+$/g, '');
}
}
</script>
</body>
</html>

原生js移除或添加样式的更多相关文章

  1. 天坑之路:用js给选中文字添加样式

    前言 本例基于react,但是实际上就是用原生js做的.兼容性做到了IE9,但是按照这个思路做是可以做到IE8甚至更低的. 需求与最初的思路 当我拿到这个需求的时候以为很简单,就是可以给页面上的文章做 ...

  2. 原生js实现类的添加和删除,以及对数据的add和update、view ,ajax请求 ,页面离开的操作

    1 类操作 function hasClass(cla, element) { if(element.className.trim().length === 0) return false; var ...

  3. 原生js实现点击添加购物车按钮出现飞行物飞向购物车

    效果演示: 思路:核心->抛物线公式 let a = -((y2-y3)*x1 - (x2-x3)*y1 + x2*y3 - x3*y2) / ((x2-x3) * (x1-x2) * (x1- ...

  4. 通过原生JS实现为元素添加事件

    自己写了一个为元素添加事件的方法,并封装到对象中. 说明: id : 目标元素的ID type: 事件的类型,注意的是不能加on fn:事件处理程序 isBubble :规定事件流 代码: var b ...

  5. 原生js获取元素非行内样式属性的方法

    获取当前对象的样式DOM标准中的全局方法 getComputedStyle(obj).width (获取元素的宽度),但在非标准IE浏览器(IE8)以下有兼容问题IE8以下要这样写 obj.curre ...

  6. 原生JS怎样给div添加链接

    html: <div href="http://www.atigege.com" target="_blank">个人网站</div> ...

  7. js实现分页列表添加样式

    <script> var dUrl=window.location.href; var cUrl=(dUrl.substring(0, dUrl.indexOf('list_'))); v ...

  8. 原生js实现tab选项卡

    1.html部分 <body>        <div id="tab">            <div class="tab_menu& ...

  9. 原生JS+Canvas实现五子棋游戏

    一.功能模块 先看下现在做完的效果: 线上体验:https://wj704.github.io/five_game.html 主要功能模块为: 1.人机对战功能 2.悔棋功能 3.撤销悔棋功能 二.代 ...

随机推荐

  1. django项目同一用户不能同时登陆

    1.session认证 ..... login(request, user) #登录成功 # 登录之后获取获取最新的session_key session_key = request.session. ...

  2. kubernetes in action - Volumes

    Volume解决Kubernetes的存储的问题 对于Pod使用的存储,抽象为volume,volume伴随着Pod的创建而创建,消失而同时消失,不能单独的创建 这样的好处,是存储的塑胶不会因为某个c ...

  3. tableview Footerview有多余的间距

    调整footerView的高度 UIView *footerV = [[UIView alloc] initWithFrame:CGRectMake(, , Main_Screen_Width, )] ...

  4. Win10问题汇总

    1.重置网络连接命令 netsh winsock reset ipconfig /flushdns 2.WIN10去除我的电脑上面的6个文件夹 把下面代码复制,保存到.reg中,然后执行即可(修改注册 ...

  5. java程序如何正确的打日志

    什么是日志 简单的说,日志就是记录程序的运行轨迹,方便查找关键信息,也方便快速定位解决问题. 我们 Java 程序员在开发项目时都是依赖 Eclipse/ Idea 等开发工具的 Debug 调试功能 ...

  6. js 转java后台传过来的list

    var intIndex=0; arrList = new Array(); arrList = "${orderNumList}".replace('[','').replace ...

  7. spring-data-mongodb中的MongoTemplate与MongoRepository

    springboot添加maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <a ...

  8. [SpringMVC]自定义注解实现控制器访问次数限制

    我们需要根据IP去限制用户单位时间的访问次数,防止刷手机验证码,屏蔽注册机等,使用注解就非常灵活了 1 定义注解 @Retention(RetentionPolicy.RUNTIME) @Target ...

  9. 玩转PIL >>> 玩转photo

    前:1.使用图片放在文件最后,需要的请自行下载 2.运行环境win10家庭版,已经安装好pillow库 一.学习总结 PIL库支持图像的储存,显示和处理,几乎能处理所有的图片格式,可以完成对图像的缩放 ...

  10. JavaWeb学习之三层架构实例(二)

    引言 这个实例是上一个实例JavaWeb学习 三层架构实例(一)的加强版,实现的是在前端对数据库中student表的 增.删.改.查 操作.关于三层组成云云,这里就不再叙述. 实例 效果图 先来看一下 ...