2010-04-23 7 views
0

I ont le code javascript:Trouble with code 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); 
} 

Fonction f_documentSize() retourne array [4] avec widnow taille. Voici ce que j'obtiens en utilisant firebug:

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

Qu'est-ce qui ne va pas?

Répondre

3

Mauvais nombre de parenthèses:

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

Vous devez:

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

En fait, il peut avoir besoin 3, ou il pourrait concaténer au lieu d'ajouter. –

+0

Juste remarqué que trop ... mis à jour – pheelicks