2010-04-23 152 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