在用CSS模拟alert时,显示位置的问题
我用css来模拟alert,请看:
<html>
<head>
<style>
.alert{
width: 30%;
position: fixed;
top: 30%;
left: 0;
right: 0;
margin: auto;
padding: 50px;
box-sizing: border-box;
background: #fcfcfc;
border-radius: 4px;
box-shadow: 0 0 4px;
text-align: center;
display: none;
}
.mask{
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .7);
position: fixed;
top: 0;
left: 0;
display: none;
}
</style>
<script>
function Simulate_alert(msg)
{
var alert = document.getElementById('alert');
var mask = document.getElementById('mask');
alert.innerHTML =msg;
alert.style.display = 'block';
mask.style.display = 'block';
setTimeout(function() {
alert.style.display = 'none';
mask.style.display = 'none';
}, 2000);
}
</script>
</head>
<body>
<div class="mask" id="mask"></div>
<div class="alert" id="alert"></div>
<button id="myBtn" onclick="clickme('hello')">click</button>
</body>
</html>
这个文件单独保存为html,我可以运行的,现在我想把这个应用在自己的程序中,我是这样做的:
把前面的CSS定义保存在一个单独的css文件,然后把函数clickme(msg)存放在本html文件中,然后
在<body>后插入两行:
<div class="mask" id="mask"></div>
<div class="alert" id="alert"></div>
之后是我原来的代码:
<div align="center">
<p class="STYLE1">插入加盟店信息</p>
</div>
<form id="form1" name="form1" method="post" action="/cater/input/insstore.php">
<p class="STYLE2">加盟店名称
<input name="uname" type="text" id="uname" onblur="this.value=Sw(this.value)" />
</p>
.....
可是在调用该Simulate_alert函数时,并没有在网页中间显示字符串,也没有变成半透明,而
只是在网页的最上面显示字符串,请问:是不是我的div的位置有错?如果要想在网页中间显
示字符串,并变成半透明,我该怎么写?