开发者

Trouble with javascript code

开发者 https://www.devze.com 2022-12-28 10:48 出处:网络
I have javascript code: function f_dialogOpen() { var e_window = document.createElement(\"div\"); e_window.style.position = \'absolute\';

I have javascript code:

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);
}

开发者_Go百科Function f_documentSize() returns array[4] with widnow size. Here is what I get using firebug:

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

What's wrong?


Wrong number of brackets:

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

You need:

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

精彩评论

暂无评论...
验证码 换一张
取 消