如何在javascript中自定义警报框的预设ok按钮时重定向页面

时间:2015-01-07 06:20:58

标签: javascript php jquery

这是我的javascript代码

<script type="text/javascript">
    Alert.render('Saved!','myurl.php');
 </script>

并且渲染功能是

function CustomAlert() {
this.render = function (dialog,url) {
    var winW = window.innerWidth;
    var winH = window.innerHeight;
    var dialogoverlay = document.getElementById('dialogoverlay');
    var dialogbox = document.getElementById('dialogbox');
    dialogoverlay.style.display = "block";
    dialogoverlay.style.height = winH + "px";
    dialogbox.style.left = (winW / 2) - (550 * 0.5) + "px";
    dialogbox.style.top = "100px";
    dialogbox.style.display = "block";
    document.getElementById('dialogboxhead').innerHTML = "Heading";
    document.getElementById('dialogboxbody').innerHTML = dialog;
    document.getElementById('dialogboxfoot').innerHTML = "<button class='btn btn-info' onclick='Alert.ok(\"" + url + "\")'>OK</button>";
}
this.ok = function (url) {
    window.location.href(url);
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
}
}
var Alert = new CustomAlert();

我的问题是,点击“确定”后页面没有重定向。按钮。请帮帮我??

2 个答案:

答案 0 :(得分:2)

window.location.href不是函数

window.location.href(url);更改为window.location.href = url;

答案 1 :(得分:0)

更改

onclick='Alert.ok(\"" + url + "\")'>

onclick='this.ok(\"" + url + "\")'>

因为在CustomAlert

的范围内未定义警报