我使用JavaScript添加图像映射。但链接不起作用。但是,如果我在IE Developer Tools(View-DOM页面)中查看生成的HTML,然后将该HTML复制回页面,则图像映射确实有效。我在body标签的页面末尾有这个脚本。我无权更改身体标签。
var newDiv = document.getElementById('Graph2');
var br = document.createElement("br");
//If area is from the Legend
if (area.type == "chartElement") {
var ctx = area.ctx;
var myMap = document.createElement("map");
myMap.id = ("mapitem"+String(j));
myMap.className = "chart_map";
myMap.lid="rsvptt0";
var myArea = document.createElement("area");
myArea.className = "dl chart_area";
myArea.lid="legendLabel";
myArea.shape="RECT";
myArea.coords="0, 0, 20, 20";
myArea.title=img.children[j].title;
myArea.ctx=img.children[j].ctx;
myArea.href="#";
myMap.appendChild(myArea);
newDiv.appendChild(myMap);
var myImage = document.createElement("img");
myImage.name = "imageitem"+String(j);
myImage.style.color ="#000000";
myImage.style.backgroundColor ="#E3D9B3";
myImage.style.border ="1pt solid #000000";
myImage.style.paddingLeft ="0px";
myImage.style.paddingTop ="0px";
myImage.style.paddingRight ="0px";
myImage.style.paddingBottom ="0px";
myImage.style.backgroundColor ="transparent";
myImage.lid="Combination Chart11";
myImage.src="../samples/images/green.jpg";
myImage.usemap="#mapitem"+String(j);
myImage.border="0" ;
newDiv.appendChild(myImage);
newDiv.appendChild(br);
生成的HTML工作正常:
<MAP id="mapitem21" class="chart_map" lid="rsvptt0"><AREA class="dl chart_area" title="Fiscal Year = 2010" href="#" shape="RECT" coords="0,0,20,20" ctx="10::1::3" lid="legendLabel" />
</MAP>
<IMG style="BORDER-BOTTOM: #000000 1pt solid; BORDER-LEFT: #000000 1pt solid; PADDING-BOTTOM: 0px; BACKGROUND-COLOR: transparent; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; COLOR: #000000; BORDER-TOP: #000000 1pt solid; BORDER-RIGHT: #000000 1pt solid; PADDING-TOP: 0px" border="0" src="http://{ipremoved}/cognos8/samples/images/green.jpg" width="14" height="14" lid="Combination Chart11" usemap="#mapitem21" />
<BR />
答案 0 :(得分:0)
您正在设置myArea.href="#"
,这应该只是强制重新加载页面 - 只需将URL放在那里而不是#
,不是吗?