簡(jiǎn)單了解JavaScript彈窗實(shí)現(xiàn)代碼
功能
點(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" 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";
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Javascript的動(dòng)態(tài)增加類的實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狫avascript的動(dòng)態(tài)增加類的實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10
TypeScript 安裝使用及基本數(shù)據(jù)類型
這篇文章主要介紹了TypeScript 安裝使用及基本數(shù)據(jù)類型,本文分步驟給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03
淺談Javascript中的12種DOM節(jié)點(diǎn)類型
DOM是javascript操作網(wǎng)頁的接口,全稱為文檔對(duì)象模型(Document Object Model)。本文將主要說明DOM節(jié)點(diǎn)類型,有需要的可以參考借鑒。2016-08-08
JS 的應(yīng)用開發(fā)初探(mootools)
昨天在公司內(nèi)部做了一個(gè)小小的技術(shù)分享,就 js 應(yīng)用開發(fā)方面跟大家談了一點(diǎn)自己的心得,最近因?yàn)楣ぷ麝P(guān)系花在這上面的時(shí)間較多也頗有些收獲,寫在這里備忘。2009-12-12

