gpt4 book ai didi

javascript - jQuery 选择器使用 usemap 属性查找图像时出现问题

转载 作者:行者123 更新时间:2023-11-30 23:47:38 26 4
gpt4 key购买 nike

我的页面中有一个图像映射:

<div id="books">
<img src="images/books.png" width="330" height="298" border="0" \
usemap="#map_books" />
<map name="map_books" id="map_books" alt="books">
<area shape="poly" coords="17,73,81,288,210,248,254,264, ..." \
href="/about" alt="books" />
</map>
</div>

我有一个函数尝试使用此 map 在文档中查找图像:

function(elemId) { // elemId = "#map_books"

if ($(elemId).attr("tagName") == "MAP") {
// find image using this map
var selector = "img [usemap=\\" + elemId + "]";
var img = $(selector);

if (img.length == 0) {
console.log("Could not find image using " + selector);
}
}

找不到图像。

无法使用 img [usemap=\#map_books] 找到图像

我已经转义了 elemId 因为它 starts with a hash并尝试了选择器的变体。

$("img [usemap$=" + elemId.substring(1) + "]")
$("img").find("[usemap=\\" + elemId + "]")

都找不到图像。有什么想法吗?

最佳答案

img[usemap=\#map_books] 之间有一个空格。

这会导致尝试将 img 的子元素与设置为 #map_books 的属性 usemap 进行匹配。

您应该使用:

var selector = "img[usemap=\\" + elemId + "]"; 

关于javascript - jQuery 选择器使用 usemap 属性查找图像时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2533600/

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