-1
我正在嘗試使用javascript進行自定義提醒,在放置函數時,您要將其重定向到哪裏。這是我有:使用InnerHTML的Javascript函數不起作用
function CustomAlert(){
this.render = function(dialog, redirect){
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 * .5)+"px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
dialogbox.innerHTML = "<div id='dialogboxhead'><img src="/images/logo.png"></img></div> +
"<div id='dialogboxbody'>" + dialog + "</div>" +
"<div id='dialogboxfoot'><div class='alertokbtn'><button onclick='Alert.ok('" + redirect + "')'>OK</button></div></div>";
}
this.ok = function(redirect){
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
window.location = redirect;
}
}
var Alert = new CustomAlert();
這是我在HTML我建立運行功能:
<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
</div>
</div>
<button class="button" onClick="Alert.render('Alert test. This text can be anything by the way', 'https://google.com');" id="btn1">Get alert</button>
它打開與文本和一切功能,但是當我按OK,它不會重定向我。
粘貼完整代碼。 –
@SumonSarker這是合法的我的完整代碼:p –
'dialogoverlay','dialogbox' ID is missing –