javascript 仿開心網好友印象功能(點擊文字彈出印象框)_典型特效

來源:互聯網
上載者:User
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta name="author" content="Chomo" /> <link rel="start" href="http://www.jb51.net" title="Home" /> <title>仿開心網好友印象功能</title> <style type="text/css"> .box{ width:500px; padding:10px; height:auto; overflow:hidden; text-align:center} .box span{ line-height:30px; height:30px;white-space:nowrap; display:inline-block; cursor:pointer} .box a,.box a:hover{ padding:10px;color:#fff; line-height:16px;font-weight:bold; font-size:14px;text-decoration:none; position:relative; border:0;} .box a:hover{ border:2px #09e solid;padding:8px;} input.cur{ border:1px #c00 outset} </style> </head> <body> <div class="box"><span>色鬼</span><span>你懂個啥</span><span>-……-</span><span>休息</span><span>帥氣</span><span>天涯地方</span><span>無法形容</span><span>才子</span></div> <input type="text" value="asd" maxlength="20" id="input-txt"/><input type="button" value="評價" id="input-btn"/> <script type="text/javascript"> function randomColor() { //16進位方式表示顏色0-F var arrHex = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]; var strHex = "#"; var index; for(var i = 0; i < 6; i++) { //取得0-15之間的隨機整數 index = Math.round(Math.random() * 15); strHex += arrHex[index]; } return strHex; } function changeColor(){ var links = document.getElementsByTagName("a"); for(var i=0;i<links.length;i++){ var bgColor = randomColor();//改變背景色的代碼,根據修去修改。 links[i].style.backgroundColor = bgColor; } } function sayHi(){ var scolor,links = document.getElementsByTagName("a"); for(var i=0;i<links.length;i++){ links[i].onmouseover = function(){ scolor = this.style.backgroundColor; this.style.color = scolor; this.style.borderColor = scolor; this.style.backgroundColor = "white"; } links[i].onmouseout = function(){ this.style.color = "white"; this.style.borderColor = ""; this.style.backgroundColor = scolor; } links[i].onmousedown = function(){ alert('你對XXX的印象是 "'+this.childNodes[0].nodeValue+'"'); } } } function addEvaluation(){ var txt = document.getElementById("input-txt"); var btn = document.getElementById("input-btn"); var divs = document.getElementsByTagName("div")[0]; if(!txt) return false; if(!btn) return false; var texts,links,spans; txt.onfocus = function(){ btn.className="cur"; } txt.onblur = function(){ btn.className=""; } btn.onclick = function(){ if(txt.value=="") { alert("請輸入一個印象詞"); return false }; texts = document.createTextNode(txt.value); links = document.createElement("a"); spans = document.createElement("span"); links.appendChild(texts); links.style.backgroundColor = randomColor(); spans.appendChild(links); divs.appendChild(spans); sayHi(); } } changeColor(); sayHi(); addEvaluation(); </script> </body> </html>
[Ctrl+A 全選 注:如需引入外部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.