功能

点击写点什么弹窗,可以输入文字。

关闭弹窗时自动保存,并且将弹窗内容转换为段落中的文字。

low没有下限

实现

step1 设置弹窗容器,包含关闭按钮和文本区域,设置display为隐藏(none),并设置在顶层。

step2 设置弹窗按钮(这里是点击段落内容呀),并书写对应的js函数(将弹窗的display显示)。

step3 设置关闭按钮的js函数,获取文本并加入到段落中,关闭弹窗(还是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" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.css" 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="/UploadFiles/2021-04-02/show.js">

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); 
}

/* 弹窗内容 */
.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";
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

标签:
JavaScript,弹窗,代码

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“简单了解JavaScript弹窗实现代码”

暂无“简单了解JavaScript弹窗实现代码”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。