微博發(fā)布功能,可發(fā)布可刪除。樣式?jīng)]設(shè)置忽略,主要知識(shí)點(diǎn)及注意點(diǎn):
創(chuàng)新互聯(lián)企業(yè)建站,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),專(zhuān)注于網(wǎng)站建設(shè)技術(shù),精于網(wǎng)頁(yè)設(shè)計(jì),有多年建站和網(wǎng)站代運(yùn)營(yíng)經(jīng)驗(yàn),設(shè)計(jì)師為客戶(hù)打造網(wǎng)絡(luò)企業(yè)風(fēng)格,提供周到的建站售前咨詢(xún)和貼心的售后服務(wù)。對(duì)于成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、成都外貿(mào)網(wǎng)站建設(shè)公司中不同領(lǐng)域進(jìn)行深入了解和探索,創(chuàng)新互聯(lián)在網(wǎng)站建設(shè)中充分了解客戶(hù)行業(yè)的需求,以靈動(dòng)的思維在網(wǎng)頁(yè)中充分展現(xiàn),通過(guò)對(duì)客戶(hù)行業(yè)精準(zhǔn)市場(chǎng)調(diào)研,為客戶(hù)提供的解決方案。
1、動(dòng)態(tài)添加節(jié)點(diǎn)標(biāo)簽。
2、內(nèi)容為空時(shí)不能發(fā)布。
3、新發(fā)布的內(nèi)容要在上面。
4、內(nèi)容刪除要同時(shí)刪除掉節(jié)點(diǎn)。
5、為保持樣式輸入框要設(shè)置為不可拖拽。
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> * {margin: 0;padding: 0;} .box{ border: 1px solid #000; width: 600px; height: auto; margin:100px auto; padding:30px 0; } textarea{ width: 450px; resize:none; margin-left: 20px; } ul li{ width: 450px; list-style: none; border-bottom: 1px dotted #ccc; margin-left:20px; line-height: 30px; color: #333; } ul li a{ float: right; font-size: 12px; } </style> <script src="../jquery-1.11.1.min.js"></script> <script type="text/javascript"> // 方法1 window.onload = function () { var box = document.getElementById("box"); var boys=box.children; var ul = document.createElement("ul"); box.appendChild(ul); boys[2].onclick = function (){ if(boys[1].value==""){ alert("輸入不能為空"); return; } var newli= document.createElement("li"); newli.innerHTML=boys[1].value+"<a href='javascript:;'>刪除</a>"; boys[1].value =""; var lis=ul.children; if(lis.length==0){ul.appendChild(newli);}else{ ul.insertBefore(newli, lis[0]); } var as=document.getElementsByTagName("a"); for (var i=0;i<as.length;i++){ as[i].onclick=function(){ ul.removeChild(this.parentNode); } } } } // 方法2 引用jQuery // $(function(){ // $("<ul></ul>").appendTo("#box"); // var $text = $("#box").find("textarea"); // var $btn = $("#box").find("button"); // $btn.on("click",function(){ // if($text.val() ==""){ // alert("請(qǐng)輸入內(nèi)容"); // return; // } // $("ul").prepend("<li>"+$text.val()+"<a href='javascript:;'>刪除</a></li>"); // $text.val(""); // $("a").on("click",function(){ // $(this).parent("li").remove(); // }) // }) // }) </script> </head> <body> <div class="box" id="box"> 微博發(fā)布:</br><textarea cols="30" rows="10"></textarea> <button>發(fā)布</button> </div> </body> </html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持創(chuàng)新互聯(lián)!
本文名稱(chēng):js實(shí)現(xiàn)微博發(fā)布小功能
文章分享:http://jinyejixie.com/article42/gcsjhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站制作、Google、手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站制作、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)