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

首頁 > 編程 > JavaScript > 正文

js仿微博動態欄功能

2019-11-19 17:27:26
字體:
來源:轉載
供稿:網友

知識有限,目前只寫了發布動態的功能,沒有寫兼容,后面再慢慢完善。嘿嘿

效果圖:

代碼如下:

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>微博</title> <style>  body, p, img, ul, li { margin: 0; padding: 0; }  body { background-image: url("http://cdn.attach.qdfuns.com/notes/pics/201612/07/212742f92tpe2wve095ttp.jpg");}  li { list-style: none; }  .box {   padding-top: 20px;   margin: 20px auto;   width: 620px;   height: 180px;   position: relative;   background-color: #ffffff;   text-align: center;  }  .box label {   font: 18px/18px "微軟雅黑";   color: #cccccc;   position: absolute;   top: 60px;   left: 40px;   cursor: text;  }  .H {   float: left;   padding: 5px 0 5px 10px;   color: #426B80;   font: 400 16px/16px "宋體";  }  textarea {   padding: 5px;   border-color: #CCCCCC;   width: 580px;   height: 80px;   resize: none;   outline:none;   font: 400 18px "微軟雅黑";   color: #333333;  }  #button {   width: 80px;   height: 34px;   display: block;   background-color: #FFC09F;   position: absolute;   top: 148px;   right: 14px;   text-align: center;   line-height: 34px;   color: #ffffff;   cursor: pointer;   /*F7671D*/  }  .dynamic {   text-align: left;   padding: 10px 10px;   width: 580px;   height: 100%;  }  .user {   position: relative;  }  .user img {   border: solid 1px #CCCCCC;   vertical-align: top;  }  .user .name {   display: block;   position: absolute;   top: 8px;   left: 60px;   font: 600 18px/18px "微軟雅黑";  }  .time{   display: block;   position: absolute;   top: 55px;   left: 80px;   font: 500 10px/10px "微軟雅黑";  }  .dynamic .user {   margin: 10px 5px 0 10px;  }  .dynamic .list {   font: 500 16px/16px "微軟雅黑";   padding-left: 70px;  } </style> <script>  window.onload = function () {   //獲取當前時間函數   function time() {    var maydate = new Date();    var Time = maydate.getFullYear() + "-" + (maydate.getMonth()+1) +"-"+maydate.getDate()+" "+maydate.getHours()+":"+maydate.getMinutes();    return Time;   }   //獲取ID函數   function $(id) {return document.getElementById(id);}   //創建節點函數   function nweChild(id,text) {    //獲得節點ID    var parent = $(id);    //獲得body所有的孩子    var child = parent.parentNode.children;    //克隆當前節點和其所有子節點    var newNode = parent.cloneNode(true);    //給當前節點的父節點插入克隆的節點    parent.parentNode.insertBefore(newNode,child[1]);    //插入的克隆節點更換ID    child[1].id = id + (child.length - 2);    //改變時間    //獲取當前id節點的所有孩子    var idChild = child[1].children;    idChild[0].innerHTML = time();    idChild[2].innerHTML = $("text").value;   }   //獲得焦點改變邊框顏色和恢復默認字體顏色   $("text").onfocus = function () {    this.style.borderColor = "#FA7D3C";    this.style.color = "#333333";   }   //失去焦點恢復默然邊框顏色,改變字體顏色   $("text").onblur = function () {    this.style.borderColor = "#CCCCCC";    this.style.color = "#CCCCCC";   }   //監聽輸入事件   $("text").oninput = function () {    if($("text").value != ""){     //隱藏提示文本     $("txt").style.display = "none";     //文本域不為空 按鈕可點擊     $("button").style.backgroundColor = "#FF8140";    }else{     //顯示提示文本     $("txt").style.display = "block";     //文本域為空 按鈕不可點擊     $("button").style.backgroundColor = "#FFC09F";    }   }   //按鈕事件   $("button").onmousemove = function () {    //當文本域不為空執行下面按鈕事件    if($("text").value != ""){     $("button").onmouseout= function () {      //如果不為空 按鈕為亮色      if($("text").value != ""){this.style.backgroundColor = "#FF8140";      }else {       //恢復按鈕為不可點擊顏色       $("button").style.backgroundColor = "#FFC09F";      }     }     //按鈕為高亮     this.style.backgroundColor = "#F7671D";     //調用節點函數,并把傳遞當前文本內容     $("button").onclick = function () {      if($("text").value != ""){       nweChild("order",$("text").value);      }      //清空當前文本      $("text").value = "";      //恢復按鈕為不可點擊顏色$("button").style.backgroundColor = "#FFC09F";      //更改提示文本內容      $("txt").innerHTML = "你看,沒騙你吧!"      //顯示提示文本      $("txt").style.display = "block";     }    }   }  } </script></head><body> <div class="box">  <span class="H">有什么新鮮事想告訴大家?</span>  <textarea name="text" id="text"></textarea>  <label for="text" id="txt">輸入一段話,點發布會有驚喜哦!</label>  <span id="button">發布</span> </div> <div class="box dynamic" id="order">  <span class="time">2016-12-07 21:20</span>  <div class="user">   <img src="http://cdn.attach.qdfuns.com/notes/pics/201612/07/212742m96ugh87fzxhuuxp.jpg" width=50; alt="頭像">   <span class="name">漫步未來</span>  </div>  <ul class="list">   <li>未來的你,一定會感謝現在拼命的自己。</li>  </ul> </div></body></html>

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东阿县| 四川省| 明光市| 永修县| 桐城市| 汶川县| 锡林郭勒盟| 文水县| 潞西市| 武鸣县| 上犹县| 鄂托克前旗| 桐庐县| 黄大仙区| 长沙市| 汉沽区| 惠东县| 射阳县| 辽阳县| 宣威市| 通榆县| 青龙| 绵竹市| 金溪县| 新化县| 襄城县| 平湖市| 定南县| 韩城市| 华池县| 惠安县| 嘉鱼县| 昌宁县| 马鞍山市| 民丰县| 巫山县| 竹北市| 久治县| 小金县| 田东县| 浦县|