我有javascript代码:
function f_dialogOpen()
{
var e_window = document.createElement("div");
e_window.style.position = 'absolute';
var n_width = 300;
var n_height = 200;
var a_docSize = f_documentSize();
e_window.style.left = ((a_docSize[0] - n_width) / 2) + a_docSize[2]) + 'px';
e_window.style.top = ((a_docSize[1] - n_height) / 2) + a_docSize[3]) + 'px';
e_window.style.zIndex = 1002;
e_window.innerHTML = 'Hello, world!';
document.body.appendChild(e_window);
}
函数f_documentSize()返回带窗口大小的数组[4]。这是我使用firebug得到的:
missing ; before statement
e_window.style.left = ((a_docSize[0] - n_width) / 2) + a_docSize[2]) + 'px';\n
怎么了?
答案 0 :(得分:3)
括号错误:
e_window.style.left = ((a_docSize[0] - n_width) / 2) + a_docSize[2]) + 'px';
e_window.style.top = ((a_docSize[1] - n_height) / 2) + a_docSize[3]) + 'px';
你需要:
e_window.style.left = (((a_docSize[0] - n_width) / 2) + a_docSize[2]) + 'px';
e_window.style.top = (((a_docSize[1] - n_height) / 2) + a_docSize[3]) + 'px';