Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中从数组到类的img src的图像_Javascript_Html_Css - Fatal编程技术网

javascript中从数组到类的img src的图像

javascript中从数组到类的img src的图像,javascript,html,css,Javascript,Html,Css,我有一些代码,它根据从数组变量到ptag[I]中选择的随机数,用box002的id=slide显示从tempmages[]到img的临时图像 我想先在类box002的imgsrc上显示tempimages[0],在删除该图像后,它会被函数Drop(ev)删除,然后tempimages[I]应该显示imgsrc,以便同样地删除 如何将图像从图像阵列tempmages显示到类框imgsrc 我使用函数displayAllImages()将图像分配给imgsrcid=slide,但它无法显示图像 bo

我有一些代码,它根据从
数组变量
ptag[I]
中选择的随机数,用
box002
id=slide
显示从
tempmages[]
img
的临时图像

我想先在类
box002
img
src
上显示
tempimages[0]
,在删除该图像后,它会被函数
Drop(ev)
删除,然后
tempimages[I]
应该显示
img
src
,以便同样地删除

如何将图像从图像阵列
tempmages
显示到类框
img
src

我使用函数
displayAllImages()
将图像分配给
img
src
id=slide
,但它无法显示图像

box002
可以拖放到任何框中

我想在每次拖放后,从框的
tempimages[]
img
src
逐个显示每个图像。如何更改代码以实现此属性

var tempimages=[];
函数rvalue(){
var数组=[];
var arrayVariable=['1','2','3','4','5','6','7','8','9','10']
var ArrayOfImages=['1.jpg'、'2.jpg'、'3.jpg'、'4.jpg'、'5.jpg'、'6.jpg'、'7.jpg'、'8.jpg'、'9.jpg'、'10.jpg'];
arrayLength=arrayVariable.length;
ptags=document.getElementsByName(“值”);
对于(i=0;i
#容器{
利润上限:-2%;
空白:nowrap;
文本对齐:居中;
左缘:20%;
保证金权利:30%;
}
.盒子{
背景颜色:珊瑚;
宽度:60px;
高度:60px;
边缘顶部:10px;
显示:内联块;
边界半径:5px;
边框:2倍实心#333;
边框颜色:#e600;
边界半径:10%;
背景色:#ffcc00;
}
.box002{
浮动:左;
宽度:50px;
高度:50px;
浮动:左;
左缘:30%;
垫面:2%;
背景色:#ffff00 2px;
边框:2px实心#000066;
}	
.文本{
填充:20px;
利润率:7像素;
边缘顶部:10px;
颜色:白色;
字体大小:粗体;
文本对齐:居中;
}
#容器{
空白:nowrap;
文本对齐:居中;
左缘:20%;
保证金权利:30%;
}
.文本{
填充:20px;
利润率:7像素;
边缘顶部:10px;
颜色:白色;
字体大小:粗体;
文本对齐:居中;
}


我不是100%确定你想要达到的目标,但这里有一些东西可以让你达到你想要的目标。它随机选取三个项目,并在每次将幻灯片放在其中一个框上后更新幻灯片元素中的图像

我做了一些更改,请参阅代码中的注释,了解我为什么做这些更改。当我第一次看到这段代码时,我不理解需要两个单独的数组,所以我将它们合并到一个数组中

var tempimages=[];
函数rvalue(){
常数
项目=[
{标签:“1”,url:'https://via.placeholder.com/75x75?text=1' },
{标签:“2”,url:'https://via.placeholder.com/75x75?text=2' },
{标签:“3”,url:'https://via.placeholder.com/75x75?text=3' },
{标签:“4”,url:'https://via.placeholder.com/75x75?text=4' },
{标签:“5”,url:'https://via.placeholder.com/75x75?text=5' },
{标签:“6”,url:'https://via.placeholder.com/75x75?text=6' },
{标签:“7”,url:'https://via.placeholder.com/75x75?text=7' },
{标签:“8”,url:'https://via.placeholder.com/75x75?text=8' },
{标签:“9”,url:'https://via.placeholder.com/75x75?text=9' },
{标签:“10”,url:'https://via.placeholder.com/75x75?text=10' }
],
ptags=Array.from(document.querySelectorAll('[name=“values”]');
ptag.forEach(ptag=>{
常数
//生成一个随机索引。
randomIndex=Math.floor(Math.random()*items.length),
//从随机索引中获取at项(可能是同一项
//多次拾取,因为没有检查重复项)。
项目=项目[随机索引];
//更新标签
ptag.textContent=item.label;
//将项目推入阵列。
tempimages.push(项目);
});
}
函数displayAllImages(){
//检查阵列中是否有静止图像,如果没有,请退出。
if(tempimages.length==0){
返回;
}
常数
//从数组中删除索引0处的项。
item=tempimages.shift(),
//获取图像元素。
image=document.getElementById('slide');
//更新src属性,使其指向新URL。
image.src=item.url;
};
$(函数(){
//开始时,先执行右值。这是从正文中的onload中获取的
//因为那是拉特发射的