2010-04-23 93 views
0

我有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] widnow大小。这是我使用萤火虫:

missing ; before statement 
e_window.style.left = ((a_docSize[0] - n_width)/2) + a_docSize[2]) + 'px';\n 

怎么了?

回答

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'; 
+0

实际上他可能需要3,或者它可以连接而不是相加。 – 2010-04-23 13:17:48

+0

只是注意到,也...更新 – pheelicks 2010-04-23 13:18:10