這篇文章給大家分享的是有關(guān)javascript怎么實(shí)現(xiàn)動(dòng)態(tài)顯示顏色塊的報(bào)表效果的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿(mǎn)足客戶(hù)于互聯(lián)網(wǎng)時(shí)代的三穗網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
利用html的顏色塊動(dòng)態(tài)展示數(shù)據(jù)
<style type="text/css"> *{ padding: 0; margin: 0; } .tubiao,.jihua,.shiji,.riqi{ width: 100%; overflow: hidden; margin-top: 10px; } .left{ width: 10%; float: left; text-align: center; height: 25px; line-height: 25px; } .right{ width: 90%; float: right; height: 25px; } span { width: 5%; height: 100%; text-align: center; display: inline-block; } </style>
<body> <div class="tubiao"> <div class="jihua"> <div class="left">計(jì)劃</div> <!--計(jì)劃span存放的地方--> <div class="right plan"></div> </div> <div class="shiji"> <div class="left">實(shí)際</div> <!--實(shí)際span存放的地方--> <div class="right act"></div> </div> <div class="riqi" id="day_id"> <!--日期存放的地方--> <div class="right day"></div> </div> </div> <script type="text/javascript"> var temp1="0-0.5-2-2-2-2-1-1";//計(jì)劃耗時(shí)(塊的單位寬度) var temp2="1-1-2-1-2-0-0-0";//實(shí)際耗時(shí)(塊的單位寬度) var temp3="5/19-5/20-5/21-5/22-5/23-5/24-5/25-5/26-5/27-5/28";//綜合日期 var temp=temp1+"~"+temp2+"~"+temp3; var plan = document.getElementsByClassName("plan")[0]; var act = document.getElementsByClassName("act")[0]; var day = document.getElementsByClassName("day")[0]; var num = 20;//創(chuàng)建多少個(gè)格 load_first(temp); //分割數(shù)據(jù)和添加色塊操作 function load_first(temp){ var demo=temp.split("~"); var d1=demo[0].split("-");//計(jì)劃耗時(shí)(塊的單位寬度)數(shù)組 var d2=demo[1].split("-");////實(shí)際耗時(shí)(塊的單位寬度)數(shù)組 var d3=demo[2].split("-");//綜合日期數(shù)組 for(var i=0;i<d3.length;i++){ time_span(d3[i]); } //alert("6:"+d1.length+"---"+"3:"+d2.length); //alert("d3.length:"+d3.length); for(var i=0;i<d1.length;i++){ add_span(d1[i],d2[i],i); } document.getElementById("day_id").style.marginLeft="-30px"; } //新增顏色塊,a為計(jì)劃顏色塊寬度,b為實(shí)際顏色塊寬度 function add_span(a,b,i){ //創(chuàng)建span塊 var span1 = document.createElement("span"); var span2 = document.createElement("span"); //定義隨機(jī)底色 var spa = "rgba(" + rnd(0,255)+ "," + rnd(0,255)+ ","+ rnd(0,255)+ ","+ rnd(0.5,1) +")";//每一個(gè)顏色隨機(jī)出來(lái) if(i==0){ span1.style.backgroundColor = "000000"; //clientWidth是對(duì)象看到的寬度(不含邊線,即border) span1.style.width = (plan.clientWidth/num*a) + "px";//計(jì)劃的每一格的寬度 //插入節(jié)點(diǎn)span1至plan plan.appendChild(span1); span2.style.backgroundColor = "000000"; span2.style.width = (plan.clientWidth/num*b) + "px";//實(shí)際的每一格的寬度 act.appendChild(span2); }else{ //alert("a:"+a+"b:"+b+"i:"+i); if(a=="0"){ span1.style.backgroundColor = "000000"; span1.style.width = (plan.clientWidth/num*a) + "px";//計(jì)劃的每一格的寬度 //插入節(jié)點(diǎn)span1至plan plan.appendChild(span1); }else{ span1.style.backgroundColor = spa; //clientWidth是對(duì)象看到的寬度(不含邊線,即border) span1.style.width = (plan.clientWidth/num*a) + "px";//計(jì)劃的每一格的寬度 //插入節(jié)點(diǎn)span1至plan plan.appendChild(span1); } if(b=="0"){ span2.style.backgroundColor = "000000"; span2.style.width = (plan.clientWidth/num*b) + "px";//實(shí)際的每一格的寬度 act.appendChild(span2); }else{ span2.style.backgroundColor = spa; span2.style.width = (plan.clientWidth/num*b) + "px";//實(shí)際的每一格的寬度 act.appendChild(span2); } } } //日期的數(shù)據(jù)插入 function time_span(time){ //創(chuàng)建span塊 var span = document.createElement("span"); span.style.width = (plan.clientWidth/num*1) + "px";//每一個(gè)span的寬度 span.innerHTML = "" + time; day.appendChild(span); } //隨機(jī)函數(shù) function rnd(min,max){ return Math.round(Math.random()*(max - min)+min); } function QueryData() { var displayStyle = "1"; $.ajax({ type: "post", url: "Test.aspx", dataType: "text", data: { "DispalyStyle": displayStyle }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown + XMLHttpRequest.responseText); }, success: function (json) { try { load_first(json); } catch (e) { } } }); } //QueryData(); </script> </body>
感謝各位的閱讀!關(guān)于“javascript怎么實(shí)現(xiàn)動(dòng)態(tài)顯示顏色塊的報(bào)表效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
當(dāng)前標(biāo)題:javascript怎么實(shí)現(xiàn)動(dòng)態(tài)顯示顏色塊的報(bào)表效果
本文來(lái)源:http://www.rwnh.cn/article10/gpodgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷(xiāo)、企業(yè)網(wǎng)站制作、定制開(kāi)發(fā)、面包屑導(dǎo)航、商城網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)