html5實作留言板的程式碼實例分享
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312"> <title>HTML5--JS API-本地存储 Web留言板</title> <style type="text/css"> *{margin:0; padding:0;} body,input{font-size:14px; line-height:24px; color:#333; font-family:Microsoft yahei, Song, Arial, Helvetica, Tahoma, Geneva;} h1{margin-bottom:15px; height:100px; line-height:100px; text-align:center; font-size:24px; color:#fff; background:#0051a1;} #content #post,#comment p{zoom:1;} #content #post:after,#comment p:after{display:block; height:0; clear:both; visibility:hidden; overflow:hidden; content:'.';} .transition{-webkit-transition:all 0.5s linear; -moz-transition:all 0.5s linear; -o-transition:all 0.5s linear; -ms-transition:all 0.5s linear; transition:all 0.5s linear;} #content{margin:0 auto; width:960px; overflow:hidden;} #content #post{margin-bottom:15px; padding-bottom:15px; border-bottom:1px #d4d4d4 dashed;} #content #post textarea{display:block; margin-bottom:10px; padding:5px; width:948px; height:390px; border:1px #d1d1d1 solid; border-radius:5px; resize:none; outline:none;} #content #post textarea:hover{border:1px #9bdf70 solid; background:#f0fbeb;} #content #post #postBt,#content #post #clearBt{margin-left:5px; padding:3px; float:right;} #comment{overflow:hidden;} #comment p{margin-bottom:10px; padding:10px; border-radius:5px;} #comment p:nth-child(odd){border:1px solid #e3e197; background:#ffd;} #comment p:nth-child(even){border:1px solid #adcd3c; background:#f2fddb;} #comment p span{display:inline; float:left;} #comment p .msg{width:738px;} #comment p .datetime{width:200px; color:#999; text-align:right;} </style> <script type="text/javascript"> var Storage = { saveData:function()//保存数据 { var data = document.querySelector("#post textarea"); if(data.value != "") { var time = new Date().getTime() + Math.random() * 5;//getTime是Date对象中的方法,作用是返回 1970年01月01日至今的毫秒数 localStorage.setItem(time, data.value + "|" + this.getDateTime());//将毫秒数存入Key值中,可以降低Key值重复率 data.value = ""; this.writeData(); } else { alert("请填写您的留言!"); } }, writeData:function()//输出数据 { var dataHtml = "", data = ""; for(var i = localStorage.length-1; i >= 0; i--)//效率更高的循环方法 { data = localStorage.getItem(localStorage.key(i)).split("|"); dataHtml += "<p><span class=\"msg\">" + data[0] + "</span><span class=\"datetime\">" + data[1] + "</span></p>"; } document.getElementById("comment").innerHTML = dataHtml; }, clearData:function()//清空数据 { if(localStorage.length > 0) { if(window.confirm("清空后不可恢复,是否确认清空?")) { localStorage.clear(); this.writeData(); } } else { alert("没有需要清空的数据!"); } }, getDateTime:function()//获取日期时间,例如 2012-03-08 12:58:58 { var isZero = function(num)//私有方法,自动补零 { if(num < 10) { num = "0" + num; } return num; } var d = new Date(); return d.getFullYear() + "-" + isZero(d.getMonth() + 1) + "-" + isZero(d.getDate()) + " " + isZero(d.getHours()) + ":" + isZero(d.getMinutes()) + ":" + isZero(d.getSeconds()); } } window.onload = function() { Storage.writeData();//当打开页面的时候,先将localStorage中的数据输出一边,如果没有数据,则输出空 document.getElementById("postBt").onclick = function(){Storage.saveData();}//发表评论按钮添加点击事件,作用是将localStorage中的数据输出 document.getElementById("clearBt").onclick = function(){Storage.clearData();}//清空所有已保存的数据 } </script> </head> <body> <h1 id="HTML-JS-nbsp-API-本地存储-nbsp-Web留言板">HTML5--JS API-本地存储 Web留言板</h1> <div id="content"> <div id="post"> <textarea class="transition"></textarea> <input id="postBt" type="button" value="发表评论"/> <input id="clearBt" type="button" value="清空所有已保存的数据"/> </div> <div id="comment"></div> </div> </body> </html>
以上是html5實作留言板的程式碼實例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

html5audioandvideoelementsenhanceFunctionality and acctibility and actificatificatifutes.1)'Concontrols'AttributeaddsStandArdPlayBackControls,而'aria-aria-label'improvesscreenReaderAccesctibility.2)

Microdatainhtml5enhancesseoanduserexperienceByByBybyBystructuredDatatoSearchEngines.1)useIteMscope,itemType,anditempropattributestomarkupcontentlikeSoreRoductSssSssSoRorevents.2)

html5introducesnewinputtypesthatenhanceSerexperience,簡化開發和iMproveAccessibility.1)自動validatesemailformat.2)優化優化,優化OmportizeSmizesemizesemizesemizesemizesemizeSmobobileWithAnumericKeyPad.3)和Simimplifydateandtimeputientupits,並重新替代了Forcustemolcustemolcustene。

H5是HTML5,是HTML的第五個版本。 HTML5提升了網頁的表現力和交互性,引入了語義化標籤、多媒體支持、離線存儲和Canvas繪圖等新特性,推動了Web技術的發展。

無障礙訪問和網絡標準遵循對網站至關重要。 1)無障礙訪問確保所有用戶都能平等訪問網站,2)網絡標準遵循提高網站的可訪問性和一致性,3)實現無障礙訪問需使用語義化HTML、鍵盤導航、顏色對比度和替代文本,4)遵循這些原則不僅是道德和法律要求,還能擴大用戶群體。

HTML中的H5標籤是第五級標題,用於標記較小的標題或子標題。 1)H5標籤幫助細化內容層次,提升可讀性和SEO。 2)結合CSS可定製樣式,增強視覺效果。 3)合理使用H5標籤,避免濫用,確保內容結構邏輯性。

HTML5構建網站的方法包括:1.使用語義化標籤定義網頁結構,如、、等;2.嵌入多媒體內容,使用和標籤;3.應用表單驗證和本地存儲等高級功能。通過這些步驟,你可以創建一個結構清晰、功能豐富的現代網頁。

通過合理的H5代碼結構可以讓頁面在眾多內容中脫穎而出。 1)使用語義化標籤如、、等組織內容,使結構清晰。 2)通過CSS佈局如Flexbox或Grid控制頁面在不同設備上的呈現效果。 3)實現響應式設計,確保頁面在不同屏幕尺寸上自適應。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

WebStorm Mac版
好用的JavaScript開發工具

Dreamweaver CS6
視覺化網頁開發工具

記事本++7.3.1
好用且免費的程式碼編輯器

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。