js實現日曆卡

來源:互聯網
上載者:User

標籤:

如下

 

首先先添加簡單的樣式

<style type="text/css">*{padding:0;margin:0;}    #tab {        margin:0 auto;        width:205px;        height:335px;        background:#e8e8e5;    }    #tab li{           width:50px;           height:50px;           background:#40403f;           float:left;           list-style:none;           margin-left:12px;           margin-top:10px;           text-align:center;           font-size:12px;           color:white;           line-height:25px;           font-weight:700;           border:1px solid #40403f;    }    #tab #text{        width:178px;        height:70px;        border:1px white solid;        background:#f0f0ef;        float:left;        position:relative;        top:10px;        left:12px;    }    #tab #text h2{        margin-left:5px;        margin-top:5px;        font-size:16px;        color:#4c4c4b;    }    #tab #text p{        margin-left:5px;        margin-top:5px;        font-size:12px;        color:#80807f;    }    #tab .active{        color:#db6082;        background:white;            }</style><div id="tab" clss="calendar">     <ul>        <li class="active"><h2>1</h2><p>JAN</p></li>        <li><h2>2</h2><p>FER</p></li>        <li><h2>3</h2><p>MAR</p></li>        <li><h2>4</h2><p>APR</p></li>        <li><h2>5</h2><p>MAY</p></li>        <li><h2>6</h2><p>JUN</p></li>        <li><h2>7</h2><p>JUL</p></li>        <li><h2>8</h2><p>AUG</p></li>        <li><h2>9</h2><p>SEP</p></li>        <li><h2>10</h2><p>OCT</p></li>        <li><h2>11</h2><p>NOV</p></li>        <li><h2>12</h2><p>DEC</p></li>    </ul>    <div id="text">            </div></div>

思路是通過一個迴圈,當滑鼠移到每個方框,顯示出不同的內容並且樣式改變

當移到每個方框,先清除每個li的樣式,以後個你滑鼠在的li給給classname就可以,

內容可以用innerHtml

js代碼如下

<script>    window.onload=function()    {        var tab=document.getElementById("tab");        var li=tab.getElementsByTagName("li");        var text1=document.getElementById("text");        // var p=text1.getElementsByTagName("p")[0];        // var h2=text1.getElementsByTagName("h2")[0];        var text=[‘快過年了,大家可以商量著去哪裡玩吧!‘,                  ‘寒假快結束了,是該時候寫作業了‘,                  ‘開學季了‘,                  ‘四月是談戀愛的季節.‘,                  ‘love‘,                  ‘you‘,                  ‘forever‘,                  ‘and‘,                  ‘alongside‘,                  ‘all‘,                  ‘day‘,                 ]        for(var i=0;i<li.length;i++)        {            li[i].index=i;            li[i].onmouseover= function()            {                     for(var i=0;i<li.length;i++)                  {                    li[i].className="";                  }                  this.className="active";                  text1.innerHTML= ‘<h2>‘+(this.index+1)+‘月活動</h2><p>‘+text[this.index]+‘</p>‘;            };        }           }</script>

  

 其實實現很簡單,可以自己試著寫,然後看看這代碼

 

js實現日曆卡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.