0

我的数组如下所示:

var imagetitle = new Array()
imagetitle[0] = "One two tree";
imagetitle[1] = "Zero One seven abc";
imagetitle[2] = "qwe qwe qwe";
imagetitle[3] = "rerere erere weqwe";

Imagetitle 稍后在 HTML 中用作标题。问题是当我这样使用它时,它只显示字符串的第一个单词,而不是完整的字符串。

function showimage() {
var div_sa_slikom = document.createElement("div");
div_sa_slikom.innerHTML = "<a href="+imagetarget[i_image]+" title="+imagetitle[i_image]+" target='_parent'><img style='border:none;' src="+imageurl[i_image]+" border='0' title="+imagetitle[i_image]+" alt="+imagetitle[i_image]+" /></a>";
var container = document.getElementById("slike_rotator");
container.appendChild(div_sa_slikom);
}
4

1 回答 1

5

您的问题是您正在构建的 HTML 缺少引号。

你正在建造

title=One two tree

代替

title="One two tree"

将您的功能替换为

function showimage() {
   var div_sa_slikom = document.createElement("div");
   div_sa_slikom.innerHTML = '<a href="'+imagetarget[i_image]+'" title="'+imagetitle[i_image]+'" target="_parent">'
       + '<img style="border:none;" src="'+imageurl[i_image]+'" border=0 title="'+imagetitle[i_image]+'" alt="'+imagetitle[i_image]+'">'
       + '</a>';
   var container = document.getElementById("slike_rotator");
   container.appendChild(div_sa_slikom);
}
于 2012-10-28T14:41:52.590 回答