这部分代码工作正常:
var cobras=new Array();
cobras[0] = '<img src="Cobra1.jpg">';
cobras[1] = '<img src="Cobra2.jpg">';
cobras[2] = '<img src="Cobra3.jpg">';
cobras[3] = '<img src="Cobra4.jpg">';
cobras[4] = '<img src="Cobra5.jpg">';
cobras[5] = '<img src="Cobra6.jpg">';
cobras[6] = '<img src="Cobra7.jpg">';
cobras[7] = '<img src="Cobra8.jpg">';
cobras[8] = '<img src="Cobra9.jpg">';
cobras[9] = '<img src="Cobra10.jpg">';
cobras[10] = '<img src="Cobra11.jpg">';
cobras[11] = '<img src="Cobra12.jpg">';
cobras[12] = '<img src="Cobra13.jpg">';
cobras[13] = '<img src="Cobra14.jpg">';
cobras[14] = '<img src="Cobra15.jpg">';
var numberChosen=Math.floor(Math.random()*15);
function makeDisappear() {
var elem = document.getElementById("main");
elem.style.visibility = "hidden";
var elem = document.getElementById("empty");
elem.style.visibility = "visible";
var bodyE1 = document.body;
bodyE1.innerHTML += cobras[numberChosen];
}
但它添加了一个左对齐的图像,我想将它对齐在中心。这是我尝试过的:
var bodyE2 = document.getElementById("parte");
bodyE2.innerHTML = cobras[numberChosen];
这就是我所说的:
<center>
<img id="parte" src=" ' + cobras[numberChosen] + ' ">
</center>
但是图像没有出现,如果我检查元素,img src="Cobras7"
图像部分的“内部”有一些东西,比如:
\/ <img id = "parte" src=" ' + cobras[numberChosen] + ' ">
<img src="Cobras7">
有任何想法吗?