您好,登錄后才能下訂單哦!
這篇文章主要講解了JavaScript彈窗的實(shí)現(xiàn)方法,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。
功能
點(diǎn)擊寫點(diǎn)什么彈窗,可以輸入文字。
關(guān)閉彈窗時(shí)自動(dòng)保存,并且將彈窗內(nèi)容轉(zhuǎn)換為段落中的文字。
low沒有下限
實(shí)現(xiàn)
step1 設(shè)置彈窗容器,包含關(guān)閉按鈕和文本區(qū)域,設(shè)置display為隱藏(none),并設(shè)置在頂層。
step2 設(shè)置彈窗按鈕(這里是點(diǎn)擊段落內(nèi)容呀),并書寫對(duì)應(yīng)的js函數(shù)(將彈窗的display顯示)。
step3 設(shè)置關(guān)閉按鈕的js函數(shù),獲取文本并加入到段落中,關(guān)閉彈窗(還是display?。?/p>
代碼
html代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>彈窗</title> <link rel="stylesheet" type="text/css" href="style.css" rel="external nofollow" > <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css" rel="external nofollow" > </head> <body> <p id="p1" onclick="writeBlog()">今天想寫點(diǎn)什么?</p> <div class="open" id="open"> <div class="open-content"> <span class="close" id="close" onclick="closeit()"><i class="fa fa-close"></i></span> <textarea class="textstyle" id="textstyle" rows="10" cols="90" placeholder="寫下生活" ></textarea> </div> </div> </body> <script type="text/javascript" src="show.js"></script> </html>
CSS代碼
/* 彈窗 (background) */ .open { display: none; /* 默認(rèn)隱藏 */ position: fixed; /* 固定定位 */ z-index: 1; /* 設(shè)置在頂層 */ left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4); } /* 彈窗內(nèi)容 */ .open-content { background-color: #fefefe; margin: 10% auto; padding: 20px; border: 1px solid #888; width: 80%; } .textstyle{ padding:20px; margin:10% auto; } /* 關(guān)閉按鈕 */ .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; }
JS代碼
function writeBlog(){ var open=document.getElementById("open"); open.style.display="block"; } function closeit(){ var text=document.getElementById("textstyle").value; document.getElementById("p1").innerHTML+="<br>"+text; document.getElementById("open").style.display="none"; }
看完上述內(nèi)容,是不是對(duì)JavaScript彈窗的實(shí)現(xiàn)方法有進(jìn)一步的了解,如果還想學(xué)習(xí)更多內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。