javascript代码问题

时间:2010-04-23 13:13:21

标签: javascript

我有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

怎么了?

1 个答案:

答案 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';