1

我有一个带有图像的弹出窗口。我想知道是否可以为我的图像设置大小。我为我的弹出窗口制作了这个脚本:

function open_win(title, description, src, alt)
{
    var img = document.createElement("img");
    img.src = src;
    img.alt = alt;

    myWindow = window.open('', '', 'width=300, height=300, left=700, top=400')
    myWindow.document.write("<div class='description'> <img src=" + src + " alt=" + alt + " >")
    myWindow.document.write("<h4>" + title + "</h4>")
    myWindow.document.write("<p>" + description + "</p></div>")

    document.body.appendChild(img)

    myWindow.focus()
}

我希望我的图片是 1185x785。我已经搜索了如何做到这一点,但我只有调整窗口大小的答案,我不需要那个。我只想调整我的图像大小。

我试过这个,但它不起作用:

img.style.width='1185px';
img.style.height='785px';
4

1 回答 1

1

我找到了答案!我只需要更改这一行:

    myWindow.document.write("<div class='description'> <img src=" + src + " alt=" + alt + " >")

有了这个

    myWindow.document.write("<div class='description'> <img src=" + src + " alt=" + alt + " width=1185 height=785 >")
于 2013-06-18T10:26:14.833 回答