为超链接添加onclick()动作,动作内容为弹出对话框。javascript提供了3种类型的对话框:
alert() : 提醒
confirm():确认,返回 true 或者 false
prompt():带输入的对话框
下面进行实例演示:
1、HTML结构
<a href="#" onclick="fun1()">你有一个礼物</a><a href="#" onclick="fun2()">我要接收礼物</a><a href="#" onclick="fun3()">必须先对暗号</a>2、javascript代码
function fun1(){ alert("你得到一个礼物!!")}function fun2(){ if(confirm("确定接收礼物?")) alert("对一下暗号先...")}function fun3(){ var code = prompt("请对暗号:") if(code) alert("给你礼物!!") else alert("蒙人呢!")}其实弹出层的思路还是比较简单的:
一般是这个层是隐藏的(display:none),然后点击你说的"图片(或者任何的页面元素)",这个层就会显示(一般display:inline-block/block),同时设置一个灰色的背景看起来这个层是浮于下面的层之上的。
下面是一段演示代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8"><title>弹出层—到浏览器中央—背景变暗</title>
<style>
*{margin:0padding:0px}
body{padding:30px}
#show{width:300pxheight:200pxdisplay:nonepadding:1pxposition:absoluteborder:1px solid #4c77aabackground:#f2f7fdz-index:11zoom:1}
#show h3{background:#4c77aacolor:#ffffont-size:14pxpadding:5px}
#show span{position:absoluteright:3pxtop:3pxdisplay:blockcursor:pointercolor:#ffffont-weight:bold}
#show p{padding:5px}
#text{font-size:12pxtext-indent:2emline-height:20px}
#bgbox{position:absoluteleft:0top:0background:#000filter:alpha(opacity=30)opacity:0.3z-index:10}
</style>
<script type="text/javascript">
function show(){
var iWidth = document.documentElement.clientWidth
var iHeight = document.documentElement.clientHeight
var bgObj = document.createElement("div")
bgObj.setAttribute("id","bgbox")
bgObj.style.width = iWidth+"px"
bgObj.style.height =Math.max(document.body.clientHeight, iHeight)+"px"
document.body.appendChild(bgObj)
var oShow = document.getElementById('show')
oShow.style.display = 'block'
oShow.style.left = (iWidth-302)/2+"px"
oShow.style.top = (iHeight-202)/2+"px"
function oClose(){
oShow.style.display = 'none'
document.body.removeChild(bgObj)
}
var oClosebtn = document.createElement("span")
oClosebtn.innerHTML = "×"
oShow.appendChild(oClosebtn)
oClosebtn.onclick = oClose
bgObj.onclick = oClose
}
</script>
</head>
<body>
<a onclick="show() return false" href="#">请猛击我(我会弹到中间,同时背景变暗)</a>
<div id="show"><h3>弹出层标题栏</h3>
<p id="text">
这里是弹出层内容,内容可以是文字、图片等,可以是iframe传进来,也可以用jQuery的load()传进来。
</p>
</div>
</body>
</html>
进弹;;就是当你打开一个网站之后会弹出一个网页,没弹一个都会增加你的收入1000;5元 就是所谓的弹窗退弹; 就是当你关闭这个网页的时候利用某个程序在谈一个窗口。(需要的话可邮件给我)也有收入。这样就会有双倍的价钱。