js實現(xiàn)模態(tài)窗口增加與刪除
更新時間:2022年07月05日 17:22:33 作者:scarsun
這篇文章主要為大家詳細(xì)介紹了js實現(xiàn)模態(tài)窗口增加與刪除,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)模態(tài)窗口增加與刪除的具體代碼,供大家參考,具體內(nèi)容如下
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模態(tài)窗口</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div id="reset">
<div id="talk">issue<span id="close">×</span></div>
<div class="group"><label> name </label> <input type="text" id="username"></div>
<div class="group"><label> Please enter content <br /></label><textarea id="content"></textarea></div>
<input type="submit" value="confirm" id="btn2">
<input type="submit" value="cancel" id="btn3">
</div>
<br />
<div id="box">
<a id="btn">Click tweet</a>
<ul id="uls">
<li>
<a href="javascript:;" class="delete">×</a>
<h4 class="username">致橡樹</h4>
<p>我如果愛你——絕不像攀援的凌霄花,借你的高枝炫耀自己;我如果愛你——絕不學(xué)癡情的鳥兒,為綠蔭重復(fù)單調(diào)的歌曲;也不止像泉源,常年送來清涼的慰藉;也不止像險峰,增加你的高度,襯托你的威儀。甚至日光。甚至春雨。</p>
</li>
</ul>
</div>
<script src="index.js"></script>
</body>
</html>
* {
margin: 0;
padding: 0;
}
body{
width:100%;
background-image: url(img/1.jpg);
}
ul,li{
list-style: none;
}
#reset{
display:none;
background:#eee;
width:500px;
height:250px;
position:absolute;
left:30%;
top:35%;
}
#reset #talk{
width: 100%;
height: 35px;
background: #ccc;
text-align: center;
line-height: 35px;
font-size: 18px;
color: #fff;
font-weight: 700;
}
#talk #close{
position:absolute;
right: 5px;
top: 0;
font-size:20px;
width:20px;
height:20px;
color: #999;
cursor:pointer;
}
#reset .group{
margin: 5px 20px;
}
#reset .group label{
color: #666;
font-size: 14px;
}
#username {
width: 200px;
height: 25px;
border: 1px solid #eee;
outline: none;
}
#content {
width: 460px;
height: 110px;
border: 1px solid #eee;
outline: none;
margin-top: 5px;
resize: none;
}
#btn2 {
margin-left: 200px;
width: 60px;
height: 25px;
border: 0;
border-radius: 5px;
background: #ddd;
font-size: 14px;
color: #666;
line-height: 25px;
}
#btn3 {
width: 50px;
height: 25px;
border: 0;
border-radius: 5px;
background: #ddd;
font-size: 14px;
color: #666;
padding: 5px;
}
#box{
margin: 0 auto;
width: 1000px;
height: auto;
background-repeat: no-repeat;
background-position: top center;
border-radius: 10px;
}
#box #btn{
display: block;
width: 150px;
text-align: center;
text-decoration: none;
color: #00ffba;
font-size: 20px;
background: #fff;
border-radius: 5px;
padding: 5px;
margin:10px ;
cursor: pointer;
}
#uls{
margin: 20px 10px 0;
background: #fff;
border-radius: 10px auto 0;
}
#uls li {
padding: 10px 5px;
border-bottom: 1px dashed #eee;
}
#uls li .username {
color:#2223218a;
padding: 2px 5px;
}
#uls li p {
padding: 10px 10px;
color: #aaa;
font-size:14px;
}
#uls li a{
float:right;
text-decoration:none;
color:#a9a9a9;
padding:0px 5px;
}
window.onload = function () {
var box = document.getElementById('box');
var btn = document.getElementById("btn");
var reset = document.getElementById("reset");
var top = document.getElementById("talk");
var close = document.getElementById("close");
var btn2 = document.getElementById("btn2");
var btn3 = document.getElementById("btn3");
btn.onclick=function(){
reset.style.display="block";
};
//關(guān)閉彈出頁
close.onclick = function(){
reset.style.display="none";
};
btn3.onclick = function(){
reset.style.display = "none";
};
//發(fā)布
btn2.onclick = function() {
var _username = username.value;
var _content = content.value;
if (_username == '') {
alert('請輸入您的姓名');
return;
}
if (_content == '') {
alert('請輸入您的留言');
return;
}
var sensitiveWords = ['共產(chǎn)黨', '土匪', '呵呵'];
sensitiveWords.forEach(function (v) {
while(_content.indexOf(v) !== -1) {
_content = _content.replace(v, '***');
}
});
// 取消發(fā)布
//限制字?jǐn)?shù)為150
function LimitNumber(txt) {
var str = txt;
str = str.substr(0,150);
_content.innerText=str;
}
if (_content.length>150){
alert("您輸入超出限制");
LimitNumber();
}
var newLi = document.createElement('li');
newLi.innerHTML = '<a href="javascript:;" class="delete">×</a>' + '<div class="username">' + _username + '</div><p>' + _content + '</p>';
uls.appendChild(newLi);
username.value = '';
content.value = '';
reset.style.display="none";
};
// 拖拽
reset.onmousedown = function (ev) {
var maxLeft = document.documentElement.clientWidth - reset.offsetWidth;
var maxTop = document.documentElement.clientHeight - reset.offsetHeight;
var e = ev || window.event;
var X = e.clientX - reset.offsetLeft;
var Y = e.clientY - reset.offsetTop;
//只針對IE瀏覽器
if(reset.setCapture) {
reset.setCapture();
}
document.onmousemove = function (ev) {
var e = ev || window.event;
var left = e.clientX - X;
var top = e.clientY - Y;
//限定范圍
if(left < 0){
left = 0;
}
if(top < 0){
top = 0;
}
if(top> maxTop ){
top = maxTop;
}
if(left > maxLeft ){
left = maxLeft;
}
reset.style.left = left + 'px';
reset.style.top = top + 'px';
};
document.onmouseup = function () {
document.onmousemove = null;
document.onmouseup = null;
//取消捕獲事件
if(reset.releaseCapture){
reset.releaseCapture();
}
};
};
};
var uls = document.getElementById('uls');
uls.onclick = function (ev) {
var e = ev || window.event;
var o = e.srcElement || e.target;
if(o.nodeName === "A") {
uls.removeChild( o.parentNode );
}
};
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript開發(fā)隨筆二 動態(tài)加載js和文件
js無非就是script標(biāo)簽引入頁面,但當(dāng)項目越來越大的時候,單頁面引入N個js顯然不行,合并為單個文件減少了請求數(shù),但請求的文件體積卻很大2011-11-11
js中用window.open()打開多個窗口的name問題
這篇文章主要介紹了js中用window.open()打開多個窗口的問題,需要的朋友可以參考下2014-03-03
js open() 與showModalDialog()方法使用介紹
項目開發(fā)中經(jīng)常要用到j(luò)s open() 與showModalDialog()方法,下面有個不錯的示例,喜歡的朋友可以研究下2013-09-09
Three.js中實現(xiàn)一個OBBHelper實例詳解
這篇文章主要介紹了Three.js中實現(xiàn)一個OBBHelper,本文參考Box3Helper源碼,并寫出一個OBBHelper,本文結(jié)合實例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-09-09

