请些一段兼容IE的JS弹窗代码,蓝色风格
时间: 2024-03-05 17:49:04 浏览: 17
好的,以下是一段兼容IE的JS弹窗代码,蓝色风格:
```javascript
function showAlert() {
var alertBox = document.createElement("div");
alertBox.style.position = "fixed";
alertBox.style.top = "50%";
alertBox.style.left = "50%";
alertBox.style.transform = "translate(-50%, -50%)";
alertBox.style.backgroundColor = "#0070c0";
alertBox.style.color = "#fff";
alertBox.style.padding = "20px";
alertBox.style.borderRadius = "5px";
alertBox.style.boxShadow = "0 0 10px rgba(0,0,0,.3)";
var message = document.createElement("p");
message.innerText = "这是一条弹窗消息!";
var closeButton = document.createElement("button");
closeButton.innerText = "关闭";
closeButton.style.backgroundColor = "#fff";
closeButton.style.color = "#0070c0";
closeButton.style.padding = "5px 10px";
closeButton.style.border = "none";
closeButton.style.borderRadius = "5px";
closeButton.style.cursor = "pointer";
closeButton.onclick = function() {
document.body.removeChild(alertBox);
};
alertBox.appendChild(message);
alertBox.appendChild(closeButton);
document.body.appendChild(alertBox);
}
```
你可以将它放在 HTML 的 head 标签内,然后在需要弹窗的地方调用 showAlert() 函数即可。