亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

簡單了解JavaScript彈窗實現(xiàn)代碼

 更新時間:2020年05月07日 09:05:52   作者:凌轢VF  
這篇文章主要介紹了簡單了解JavaScript彈窗實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

功能

點擊寫點什么彈窗,可以輸入文字。

關閉彈窗時自動保存,并且將彈窗內(nèi)容轉換為段落中的文字。

low沒有下限

實現(xiàn)

step1 設置彈窗容器,包含關閉按鈕和文本區(qū)域,設置display為隱藏(none),并設置在頂層。

step2 設置彈窗按鈕(這里是點擊段落內(nèi)容呀),并書寫對應的js函數(shù)(將彈窗的display顯示)。

step3 設置關閉按鈕的js函數(shù),獲取文本并加入到段落中,關閉彈窗(還是display啊)

代碼

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()">今天想寫點什么?</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; /* 默認隱藏 */
  position: fixed; /* 固定定位 */
  z-index: 1; /* 設置在頂層 */
  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;
}
/* 關閉按鈕 */
.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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論