如何在通过覆盖修改后再次设置 javascript 警报的默认行为
how to set default behavior of javascript alert again after modifying by overriding
我已经覆盖并修改了警报框的功能,它工作正常,但问题是我已经修改了某些情况下的现有警报()框,但对于所有情况,我修改后的警报只有在我不加载页面。
请找出我在覆盖警报后写的代码。
<logic:notEmpty name="kvbmsg" scope="request">
<style>
#alertBox{
position:absolute;
top:300px;
left:500px;
border:solid 2px black;
background-color: #cec8c8;
padding: 50px;
font-weight:bold;
visibility: hidden;
}
#alertClose{
position: absolute;
right:0;
top: 0;
background-color: #cec8c8;
border: solid 2px #cec8c8;
color: white;
width: 1em;
padding-right: 10px;
text-align: center;
cursor: pointer;
}
</style>
<script>
window.alert = function(msg){
var id = "alertBox", alertBox, closeId = "alertClose", alertClose;
alertBox = document.createElement("div");
document.body.appendChild(alertBox);
alertBox.id = id;
alertBox.innerHTML = msg;
alertClose = document.createElement("div");
alertClose.id = closeId;
alertClose.innerHTML = "<img src=\"/ttk/images/Cancel.png\" width=\"20px\" height=\"20px\">";
alertBox.appendChild(alertClose);
alertBox.style.visibility = "visible";
alertClose.style.visibility = "visible";
alertClose.onclick = closeAlertBox;
};
function closeAlertBox(){
var alertBox = document.getElementById("alertBox");
var alertClose = document.getElementById("alertClose");
alertBox.style.visibility = "hidden";
alertClose.style.visibility = "hidden";
}
alert("<img src=\"/ttk/images/info_icon.png\" width=\"20px\" height=\"20px\">"+" "+"<%=request.getAttribute("kvbmsg")%>");
</script>
</logic:notEmpty>
<logic:notEmpty name="kvbmsgnull" scope="request">
<script>
alert("<%=request.getAttribute("kvbmsgnull")%>");
</script>
</logic:notEmpty>
所以请建议我如何在 javascript 中完成任务后再次保留警报的默认行为而无需再次加载页面。
您可以将变量设置为警报函数的引用,然后再将警报设置为该变量。
var tempAlert = window.alert
.
.
.
window.alert = tempAlert
我已经覆盖并修改了警报框的功能,它工作正常,但问题是我已经修改了某些情况下的现有警报()框,但对于所有情况,我修改后的警报只有在我不加载页面。 请找出我在覆盖警报后写的代码。
<logic:notEmpty name="kvbmsg" scope="request">
<style>
#alertBox{
position:absolute;
top:300px;
left:500px;
border:solid 2px black;
background-color: #cec8c8;
padding: 50px;
font-weight:bold;
visibility: hidden;
}
#alertClose{
position: absolute;
right:0;
top: 0;
background-color: #cec8c8;
border: solid 2px #cec8c8;
color: white;
width: 1em;
padding-right: 10px;
text-align: center;
cursor: pointer;
}
</style>
<script>
window.alert = function(msg){
var id = "alertBox", alertBox, closeId = "alertClose", alertClose;
alertBox = document.createElement("div");
document.body.appendChild(alertBox);
alertBox.id = id;
alertBox.innerHTML = msg;
alertClose = document.createElement("div");
alertClose.id = closeId;
alertClose.innerHTML = "<img src=\"/ttk/images/Cancel.png\" width=\"20px\" height=\"20px\">";
alertBox.appendChild(alertClose);
alertBox.style.visibility = "visible";
alertClose.style.visibility = "visible";
alertClose.onclick = closeAlertBox;
};
function closeAlertBox(){
var alertBox = document.getElementById("alertBox");
var alertClose = document.getElementById("alertClose");
alertBox.style.visibility = "hidden";
alertClose.style.visibility = "hidden";
}
alert("<img src=\"/ttk/images/info_icon.png\" width=\"20px\" height=\"20px\">"+" "+"<%=request.getAttribute("kvbmsg")%>");
</script>
</logic:notEmpty>
<logic:notEmpty name="kvbmsgnull" scope="request">
<script>
alert("<%=request.getAttribute("kvbmsgnull")%>");
</script>
</logic:notEmpty>
所以请建议我如何在 javascript 中完成任务后再次保留警报的默认行为而无需再次加载页面。
您可以将变量设置为警报函数的引用,然后再将警报设置为该变量。
var tempAlert = window.alert
.
.
.
window.alert = tempAlert