国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > HTML > 正文

Html 實(shí)現(xiàn)動(dòng)態(tài)顯示顏色塊的報(bào)表效果(實(shí)例代碼)

2024-08-26 00:19:29
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

利用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>

以上所述是小編給大家介紹的Html 實(shí)現(xiàn)動(dòng)態(tài)顯示顏色塊的報(bào)表效果(實(shí)例代碼),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VeVb武林網(wǎng)網(wǎng)站的支持!


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到HTML教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 平和县| 开封县| 吐鲁番市| 朝阳市| SHOW| 吉安市| 屏边| 南江县| 札达县| 金寨县| 顺昌县| 永仁县| 华蓥市| 铜山县| 大连市| 盐津县| 凤翔县| 林甸县| 宜兰县| 滦南县| 南川市| 治多县| 舒城县| 湖北省| 柘城县| 建湖县| 高密市| 亳州市| 承德市| 南投市| 涪陵区| 邵阳县| 呼伦贝尔市| 青浦区| 五常市| 益阳市| 自贡市| 积石山| 亳州市| 海城市| 墨脱县|