我问的原因是,当我在render()
中只有一个参数时,似乎工作得很好但是当我添加第二个时,它会抛出一个Uncaught SyntaxError: Unexpected token }
。
这是我的代码:
create.ejs [JS]
if (url.indexOf('?alert') != -1) {
Alert.render('Record has been created!', 'Create');
}
customAlert.js
var Alert = new CustomAlert();
function CustomAlert() {
this.render = function(body, head) {
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogOverlay = document.getElementById('dialogOverlay');
var dialogBox = document.getElementById('dialogBox');
dialogOverlay.style.display = "block";
dialogBox.style.left = (winW/2) - (550 * 0.5) +"px";
dialogBox.style.top = "200px";
dialogBox.style.visibility = "visible";
document.getElementById('dialogBoxHead').innerHTML = head;
document.getElementById('dialogBoxBody').innerHTML = body;
document.getElementById('dialogBoxFoot').innerHTML = '<button id="customBtn" onclick="Alert.ok(' + JSON.stringify(head) + ')">OK</button>';
};
this.ok = function(selected){
document.getElementById('dialogBox').style.display = "none";
document.getElementById('dialogOverlay').style.display = "none";
if (selected != 'Oops!') {
location.replace("http://localhost:3000/software");
} else {
location.replace("http://localhost:3000/home");
}
};
}
它会在create:2
上抛出异常,这只是<html>
标记吗?
知道为什么会这样吗?
还值得一提的是,我有另一个名为customDelete.js
的自定义提醒,它按预期工作,但只传递1个参数render()