gpt4 book ai didi

JavaScript 图像映射代码不起作用

转载 作者:行者123 更新时间:2023-11-30 23:50:59 24 4
gpt4 key购买 nike

这段代码有什么问题?为什么我的图像映射不起作用?

function createimg()
{
var img = new Image();
img.src='link/to/image';
img.alt='Next image'; img.id = 'span1'; img.style.zIndex = 10;
img.style.position = 'absolute';
img.style.display='block';
img.style.top = '130px';
img.style.padding='10px';
img.style.left='440px';
img.usemap='#testmap';
img.className ='dynamicSpan';
document.body.appendChild(img);

var mymap = document.createElement('map');
mymap.name = 'testmap';
document.body.appendChild(mymap);

var areatag = document.createElement('area');
areatag.shape = 'rect';
areatag.coords = '900,200,1100,1000' ;
areatag.href = 'http://www.google.com';
mymap.appendChild(areatag);
document.body.appendChild(areatag);

return img;
}

更新:

我像这样重建了我的代码,但它仍然不起作用:

 function createimg()
{
var img = new Image();
img.src='link/to/image';
img.alt='Next image';
img.id = 'span1';
img.style.zIndex = 10;
img.style.position = 'absolute';
img.style.display='block';
img.style.top = '130px';
img.style.padding='10px';
img.style.left='440px';
img.usemap='#testmap';
img.className ='dynamicSpan';


var mymap = document.createElement('map');
mymap.name = 'testmap';
mymap.id = 'testmap';


var areatag = document.createElement('area');
areatag.shape = 'rect';
areatag.coords = '0,0,500,500' ;
areatag.href = 'http://www.google.com';
areatag.target = '_blank';


//append area to map
mymap.appendChild(areatag);
// append map to document
document.body.appendChild(mymap);
//append image to document
document.body.appendChild(img);

return img;
}

最佳答案

解决方案如下:

你应该使用

img.setAttribute("usemap", '#testmap')

而不是:

img.usemap = "#testmap"

关于JavaScript 图像映射代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1537494/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com