让我解释一下:当您在JS中调用alert()时,警报下方的所有代码都将停止,当您单击Ok时,代码将返回工作.
我使用以下代码创建自己的自定义警报:
function cAlert()
{
var bOn;
this.show = function (content)
{
bOn = true;
document.write('<div id="turnOffLight"></div><div id="cAlertBox"><div id="cAlertImageBox"><img style="position: absolute; top: 54%; left: 50%; margin-top: -32px; margin-left: -32px;" src="Images/Vectors/1429744831_678136-shield-warning-64.png" alt=""/> </div><div id="cAlertContentBox"> </div><div id="cAlertButtonBox"><input id="cAlertButtonStyle" type="button" value="OK" onclick="cAlert.ok()" /></div></div>');
$("#cAlertContentBox").html(content);
$("#cAlertBox").show();
$("#turnOffLight").fadeIn("fast");
var div = document.getElementById('cAlertBox').offsetWidth;
var res = -Math.abs(div / 2);
document.getElementById('cAlertBox').style.marginTop = res + "px";
};
this.ok = function ()
{
$("#cAlertBox").hide();
$("#turnOffLight").fadeOut("medium");
bOn = false;
};
}
Run Code Online (Sandbox Code Playgroud)
在其他页面中:
<head>
<script src="Scripts/jQuery_1.11.2.js" type="text/javascript"></script>
<script src="Scripts/cAlertScript.js" type="text/javascript"></script>
<script type="text/javascript">var cAlert = new cAlert();</script>
</head>
Run Code Online (Sandbox Code Playgroud)
但我有一个问题,在登录页面,调用cAlert()后,我称之为:
echo "<script>javascript:history.go(-1)</script>";
Run Code Online (Sandbox Code Playgroud)
返回到最后一页,当我以前使用alert()时,只有在用户点击确定后,浏览器才会返回到最后一页,但是使用cAlert,浏览器已经返回到最后一页.
我想要的是用户需要单击Ok按钮将代码继续作为alert().
由于您只想在单击“确定”按钮后返回页面,因此请将函数调用或返回代码放置在函数中cAlert.ok()。这样,只有当用户单击“确定”按钮后,页面才会返回,因为只有当用户单击“确定”按钮时才会调用此函数。
this.ok = function ()
{
$("#cAlertBox").hide();
$("#turnOffLight").fadeOut("medium");
bOn = false;
window.history.go(-1);
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1074 次 |
| 最近记录: |