Javascript 如何显示包含随机数的URL中的图像?
我正试图用PubChem制造某种化合物发生器。我已经成功地生成了一个带有随机数的网站链接(例如),以及一个指向图像的链接(例如)。但是,当我尝试将随机图像链接嵌入到文档中时,它没有显示出来。说到编程,我只是个新手Javascript 如何显示包含随机数的URL中的图像?,javascript,html,image,random,hyperlink,Javascript,Html,Image,Random,Hyperlink,我正试图用PubChem制造某种化合物发生器。我已经成功地生成了一个带有随机数的网站链接(例如),以及一个指向图像的链接(例如)。但是,当我尝试将随机图像链接嵌入到文档中时,它没有显示出来。说到编程,我只是个新手 var下限=0; var上限=100000000; var rand=(Math.floor(Math.random()*(上-下))+下) 变量url=”https://pubchem.ncbi.nlm.nih.gov/compound/“+兰特 变量img=”https://pu
var下限=0;
var上限=100000000;
var rand=(Math.floor(Math.random()*(上-下))+下)
变量url=”https://pubchem.ncbi.nlm.nih.gov/compound/“+兰特
变量img=”https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?cid=“+rand+”&t=l”
文件。填写(“”);
文件。写(“”);
document.write(“”)
rand
保存一个整数。首先尝试将其更改为字符串:
var rand = (Math.floor(Math.random()*(upper-lower))+lower).toString()
javascript的HTML输出错误。看看javascript的最后一行:
var下限=0;
var上限=100000000;
var rand=(Math.floor(Math.random()*(上-下))+下);
变量url=”https://pubchem.ncbi.nlm.nih.gov/compound/“+兰特;
变量img=”https://pubchem.ncbi.nlm.nih.gov/image/imgsrv.fcgi?cid=“+rand+”&t=l”
文件。写(“”);
文件。写入(“”);
文件。写入(“”)代码>数字在合并成字符串时会自动转换成字符串。我尝试过这个方法,但仍然得到一个空图像。