样式效果如下,点击商品详情 添加样式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. 为什么局部变量必须以final修饰(或者有final实效:java8)才可以在内部类中使用?

    为什么局部变量必须以final修饰(或者有final实效:java8)才可以在内部类中使用? public class Ace { public static void main(String[] a ...

  2. onu-reg-unreg.vbs

    Sub Main crt.Sleep 10000 Dim cnt For cnt = 0 To 1000000 crt.screen.Send "admin-status down" ...

  3. python3 Django集成Ueditor富文本编辑器

    1.下载 python3: https://github.com/twz915/DjangoUeditor3/ (直接下载zip) 2.解压,解压打开后找到DjangoUeditor将DjangoUe ...

  4. socks-proxy---with ssh

    socks-proxy---with sshhttps://blog.csdn.net/scien2011/article/details/54562501

  5. [转]理解 Bias 与 Variance 之间的权衡----------bias variance tradeoff

    有监督学习中,预测误差的来源主要有两部分,分别为 bias 与 variance,模型的性能取决于 bias 与 variance 的 tradeoff ,理解 bias 与 variance 有助于 ...

  6. Springboot 学习教程(一):版本+ jdk 版本 + Maven 版本的匹配

    Spring boot 版本 Spring Framework jdk 版本 maven 版本 1.2.0 版本之前   6 3.0 1.2.0 4.1.3+ 6 3.2+ 1.2.1 4.1.3+ ...

  7. .Net新利器Rider的破解安装与使用

    准备 介绍 Rider 是 JetBrains 提供的一款用于 .Net 开发的 IDE,相对于 VS,它显得更加轻量(才 500m 左右),并且不管是提示功能还是流畅度都不逊色于 VS 且某方面可能 ...

  8. python安装画图模块pillow

    步骤一: install pillow (注意导入是 import PIL )       步骤二:如果pycharm中import选择不到,则需要在settings中导入下             ...

  9. python中pip升级

    第一步: 首先安装python,在百度中搜索python,进入python官网,点击downliad, 下载到本地: 下载好后进行安装,与一般软件安装过程一样.安装过程中要注意勾线Add python ...

  10. SSH整合时多表关联查询出现Javassist增强失败

    Customer类对应的表为另一个表LinkMan的外键,在进行LinkMan表操作时,出现如下错误. 遇到Javassist增强失败网上说法不一,有的说Customer没有无参构造方法,javass ...