检索和分配相应的与,高度和与在Javascript中的图像

retrieving and assigning corresponding with and height and with of images in Javascript

本文关键字:Javascript 图像 高度 检索 分配      更新时间:2023-09-26

我正在开发一个幻灯片应用程序。我有一个带有相应图像的复选框。因此,当用户选择复选框并单击continue按钮时,应该通过javascript检索相应的图像并设置其高度和宽度。如果一个特定的图像没有指定高度/宽度,它将被填充为height=",否则它将被填充为width = height=valuepx。我如何做到这一点…我可以得到数组的图像,但我如何检索相同的高度和宽度的相应图像。请帮助……我是JS的初学者。

function insert_slide()
{ var height;

var宽度;

var img=new Array();
var count=0;
var names=document.getElementsByName('image_id');//name of checkboxes

for(i=0;i<names.length;i++)
    {
if(names[i].checked)
    {count=count+1;
    img[i] = "<IMG SRC='" + names[i].value + "'";

    if(height != '') {
        img[i] += " height='" + height[i] + "'";
        }
    else{
    img[i] += " height='"+""+  "'"; 
        }
    if(width != '') {
        img[i] += " width='" + width[i] + "'"; 
    }
else{
img[i] += " width='"+""+  "'"; 
}
}

}

}

您刚刚声明了宽度/高度,因此它们的值是未定义的。你想如何处理宽度和高度以及它们的值?