jquery表格动态添加及各行变色效果
2016-11-10 16:21
489 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>表格动态添加及各行变色效果</title> <script src="js/jquery-1.11.1.js"></script> <style type="text/css"> *{padding: 0;margin: 0;list-style: none;} body{ width: 1000px; margin:30px auto;} .box-head { background:#009cc3;border-radius: 5px 5px 0px 0px;max-height: 40px;} .box-content { background: #eee;border: 1px solid #bbb;border-top: none; border-radius: 0 0 3px 3px;padding:10px;} .small_ico3{font-size: 16px;color: #ffffff; line-height: 40px; padding-left:10px;} .table_ban{ background: url("img/kacha.png") no-repeat center 12px #ffffff; overflow: hidden; padding-bottom: 10px;} .table_boxl{float:left; margin-left:20px;} .table_boxr{float:right;margin-right:20px;} color: #ffffff!important; padding-left:38px; background: url("img/moredjbg.png") no-repeat; margin:10px 0;} .table {border:1px solid #1295b6;border-right-width:0;display:inline-block;} .table ul li{float:left;width:180px;text-align:center; border-right:1px solid #1295b6; cursor:pointer;position:relative;} .table ul{clear:both;margin-bottom:0;padding-left:0;< 4000 span class="hljs-rule">} .table .lis1{width:70px;} .table .tit{line-height:30px;font-weight:bold;background:#8fd3e4;height:30px;} .table .tr{border-top:1px solid #1295b6;line-height:28px;height:28px;} .col{color:red;font-weight:normal;} .linebox{ float: left; background: url("img/lineline.png") repeat-y center; width:46px; height:604px; margin:58px 0 0 12px; } </style> </head> <body> <div class="box" style="width:100%;"> <div class="box-head"> <h2 class="small_ico3">数据表</h2> </div> <div class="box-content "> <div class="table_ban"> <div class="table_box table_boxl"> <h5>数据1</h5> <div class="table" id="cys_form"> <ul class="tit"> <li class="lis1">名次</li> <li>企业</li> <li>区域</li> </ul> <!--<ul class="tr">--> <!--<li class="lis1">1</li>--> <!--<li>顺丰 (<strong class="col">98%</strong>)</li>--> <!--<li>顺丰 (<strong class="col">98%</strong>)</li>--> <!--</ul>--> </div> </div> <div class="linebox"></div> <div class="table_box table_boxr"> <h5>数据2</h5> <div class="table" id="djl_form"> <ul class="tit"> <li class="lis1">名次</li> <li>企业</li> <li>区域</li> </ul> <!--<ul class="tr">--> <!--<li class="lis1">1</li>--> <!--<li>顺丰 (<strong class="col">98%</strong>)</li>--> <!--<li>顺丰 (<strong class="col">98%</strong>)</li>--> <!--</ul>--> </div> </div> </div> </div> </div> <script> $(function () { var table_cys1=['圆通','申通','天天','德邦','全峰','国通','EMS','百世','韵达','宅急送','速尔','优速','快捷','中国邮政','圆通','国通','EMS','百世','韵达','宅急送']; var table_cys2=['100','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200']; var table_cys3=['圆通','申通','天天','德邦','全峰','国通','EMS','百世','韵达','宅急送','速尔','优速','快捷','中国邮政','圆通','国通','EMS','百世','韵达','宅急送']; var table_cys4=['100','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200','200']; var table_djl1=['圆通','申通','天天','德邦','全峰','国通','EMS','百世','韵达','宅急送','速尔','优速','快捷','中国邮政','圆通','国通','EMS','百世','韵达','宅急送']; var table_djl2=['98%','98%','98%','98%','98%','98%','98%','200','200','200','200','200','200','200','200','200','200','200','200','200']; var table_djl3=['圆通','申通','天天','德邦','全峰','国通','EMS','百世','韵达','宅急送','速尔','优速','快捷','中国邮政','圆通','国通','EMS','百世','韵达','宅急送']; var table_djl4=['100','200','98%','200','200','98%','200','200','98%','200','98%','200','200','200','200','200','200','200','200','200']; var num=table_cys1.length; /////////////查验数///////////////// for(var i=0;i<num;i++){ var $cystable_ul=$('<ul class="tr"></ul>'); var $cystable_li1=$('<li class="lis1">'+(i+1)+'</li>'); var $cystable_li2=$('<li>'+table_cys1[i]+'(<strong class="col">'+table_cys2[i]+'</strong>)</li>'); var $cystable_li3=$('<li>'+table_cys3[i]+'(<strong class="col">'+table_cys4[i]+'</strong>)</li>'); $cystable_ul.append($cystable_li1); $cystable_ul.append($cystable_li2); $cystable_ul.append($cystable_li3); $('#cys_form').append($cystable_ul); } /////////////登记率///////////////// for(var i=0;i<num;i++){ var $djltable_ul=$('<ul class="tr"></ul>'); var $djltable_li1=$('<li class="lis1">'+(i+1)+'</li>'); var $djltable_li2=$('<li>'+table_djl1[i]+'(<strong class="col">'+table_djl2[i]+'</strong>)</li>'); var $djltable_li3=$('<li>'+table_djl3[i]+'(<strong class="col">'+table_djl4[i]+'</strong>)</li>'); $djltable_ul.append($djltable_li1); $djltable_ul.append($djltable_li2); $djltable_ul.append($djltable_li3); $('#djl_form').append($djltable_ul); } $('.tr').each(function () { var a=$(this).index()%2; if(a===0){ $(this).css("background","#e5e5e5")}; if(a===1){ $(this).css("background","#ffffff")}; }); $('.tr').mouseenter(function () { $(this).css("background","#b1e1eb"); }) $('.tr').mouseleave(function () { var a=$(this).index()%2; if(a===0){ $(this).css("background","#e5e5e5")}; if(a===1){ $(this).css("background","#ffffff")}; }) }) </script> </body>
效果图显示:
相关文章推荐
- 使用jquery动态添加的文本框和下拉框效果
- jQuery动态添加、删除表格行
- jquery实现弹窗效果与表格中信息的添加
- jquery方式的表格效果(隔行变色,单行高亮)
- JQuery动态操作表格(添加、删除、多选、全选删除行操作)
- 应用jQuery实现表格数据的动态添加与统计
- javascript表格操作大全:表格排序/倒序、动态添加列、批量删除、删除一行、隔行变色、鼠标悬浮切换背景色、全选/反选。(IE、火狐都兼容)
- jQuery实现HTML表格隔行变色及鼠标悬停变色效果 .
- 利用jquery 动态添加删除表格行
- jquery 动态在表格后面添加一行笔记
- 鼠标经过表格行时,显示变色、字体放大效果 jquery
- jquery动态添加表格
- 最近使用jquery比较多,网上搜了很多有用的东西,先记下来!(1.动态添加表格行, 2.下拉框联动)
- [原创]持续给力:jQuery实现表格隔行变色效果案例详解
- JQuery动态操作表格(添加、删除、多选、全选删除行操作)
- jQuery实现HTML表格隔行变色及鼠标悬停变色效果
- jQuery——动态给表格添加序号
- JQuery动态添加删除表格
- 使用jQuery动态创建一个表格,根据用户数输入的内容添加一行数据