简体   繁体   English

我要让我的 javascript 从我的图像文件夹中保留一张随机图像,在写完所有代码后图像没有显示,我不知道为什么

[英]i am to make my javascript keep a random image from my image folder, after writing all the codes the image is not showing and i don't know why

var randomNumber1 = Math.floor(Math.random()*6) + 1;
var diceName = "images/dice" + randomNumber1 + ".png"

document.querySelectorAll("img")[0].setAttribute("src", "diceName")

You are setting a string literal to src attribute.您正在将字符串文字设置为 src 属性。

remove quotes from "diceName".从“diceName”中删除引号。

 document.querySelectorAll("img")[0].setAttribute("src", diceName)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在努力在 javascript 中追加行,但我实际上不知道如何在行单元格中添加 append 图像 - I am working on appending row in javascript but I actually don't know how to append an image in row cell 想要从API提取图像,但是我的代码仅显示文本。 - Want to extract Image from API but my codes only show the text.. May i know what is wrong? 遍历所有图像后,如何使我的javascript图像库重新开始? - How would I make my javascript image gallery return to the start after it has gone through all the images? 我不明白为什么一些随机颜色与图像重叠? - I don't understand why some of the random colors are overlapping the image? 为什么我不能在javascript中更改我的图像的CSS属性? - Why can't I change CSS attributes of my image in javascript? 我的地理位置(javascript)无法正常运行,我也不知道为什么 - my geolocation(javascript) does not work and I don't know why 我不知道为什么当我在我的 HTML 程序上单击“Click = Past”按钮时,绿色字符图像不显示我在可汗学院尝试过 - I don't know why When I click the button "Click = Past" on my HTML program the green character image doesn't show up I tried to this in Khan academy 如何从文件夹中选择随机图像(jpg)到 javascript - how can I pick a random image(jpg) from a folder into javascript 我想知道为什么这不起作用,我要做的就是获取图像并将其用作画布的舞台儿童 - I want to know why this is not working, all im trying to do is get an image and use it as a stage child for my canvas 当我将鼠标悬停在图片上时,我希望它一直放大直到不再将鼠标放在上面 - When I mouse over an image, I want it to keep enlarging until I don't have my mouse on it anymore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM