主要是想用这个代替js的function abc(){ alert(“cba”);}。
因为个人觉得那种对话框用户体验不好,我想以后会尽量避免alert方法的使用,转向弹出一个div对话框的方式。
- 首先是css代码:
<style>
.white_content {
display: none;
position: absolute;
top: 25%;
left: 25%;
width: 50%;
padding: 6px 16px;
border: 12px solid #D6E9F1;
background-color: white;
z-index:1002;
overflow: auto;
}
.black_overlay {
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color:#f5f5f5;
z-index:1001;
}
.close {
float:right;
clear:both;
width:100%;
text-align:right;
margin:0 0 6px 0
}
.close a {
color:#333;
text-decoration:none;
font-size:14px;
font-weight:700
}
.con {
text-indent:1.5pc;
line-height:21px
}
/* green */
.green {
color: #e8f0de;
border: solid 1px #538312;
background: #64991e;
}
</style>
给出js代码:
<script>
function show(tag){
var light=document.getElementById(tag);
var fade=document.getElementById(‘fade’);
light.style.display=’block’;
fade.style.display=’block’;
}
function hide(tag){
var light=document.getElementById(tag);
var fade=document.getElementById(‘fade’);
light.style.display=’none’;
fade.style.display=’none’;
}
</script>
最后是html代码:
<body onload=”show(‘light’)”>
<a href=”javascript:void(0)” onclick=”show(‘light’)”>提示</a>
<div id=”light” class=”white_content”>
<div class=”con”> <center><h1><p style=”line-height:48px;”>内容1</p><p style=”line-height:48px;”>内容1</p><p style=”line-height:48px;”>内容1</p><p style=”line-height:48px;”>内容1</p><p style=”line-height:48px;”>内容1<br/>
</p><center><a class=”button green” href=”http://yunef.com/member/”><font color=”#FFFFFF”>选择</font></a> <a href=”javascript:void(0)” class=”button green” onclick=”hide(‘light’)”><font color=”#FFFFFF”>关闭框</font></a></center></h1></center></div>
</div>
<div id=”fade” class=”black_overlay”></div>
</body>
上面的代码我还会继续优化,尽量使之能实现自适应屏幕,后续可能也会贴出来。
还有js的confirm(“abcd”);和prompt(“abcde”);两个方法,我也想写一些用div实现的方式,后续有时间再做吧。