从逻辑上讲,我希望在div中的链接中嵌入图像。我已经成功地使用链接或图像实现了这一点。为了我的目的,我甚至用链接和图像并行(这是无用的)。但似乎不能将图像包装在div中的链接中。
var div = OpenLayers.Util.createDiv();
var img = OpenLayers.Util.createImage(null, null, null, null, null, null, null, delayDisplay);
img.className = "olAlphaImg";
img.alt = altText;
var link = document.createElement("a");
// link.setAttribute("href", "#");
link.href="#" + altText;
link.appendChild(img);
div.appendChild(link);
OpenLayers.Util.modifyAlphaImageDiv(div, id, px, sz, imgURL, position, border, sizing, opacity, altText);
return div;这是针对OpenLayers的,我正在尝试确保键盘导航。我只是不确定如何使用javascript来做到这一点,并且所有的例子都只使用了一个appendChild引用。我尝试过使用innerHTML(),但是我没有使用字符串,所以看起来没有什么用处。
发布于 2012-04-05 21:04:09
你说的是什么意思?
似乎不能将图像包装在div内的链接中
您是否遇到过任何错误?
我可能误解了你的问题,但如果没有,你的代码应该可以工作。
下面是我的示例:一个,它将图像包装到某个容器的链接中。
var img = document.createElement('img');
img.src = 'https://www.google.fr/images/srpr/logo3w.png';
var anchor = document.createElement('a');
anchor.href = 'http://google.com';
// Wrap image in the link (anchor):
anchor.appendChild(img);
// Insert the anchor into container:
document.getElementById('container').appendChild(anchor);https://stackoverflow.com/questions/10028981
复制相似问题