gpt4 book ai didi

javascript - 将图像大小调整为弹出窗口

转载 作者:行者123 更新时间:2023-11-28 02:10:32 24 4
gpt4 key购买 nike

我有一个弹出窗口,其中包含图像。我想知道是否可以为我的图像设置尺寸。我为我的弹出窗口制作了这个脚本:

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

最佳答案

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

    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 >")

关于javascript - 将图像大小调整为弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com