我的页面中有一个图像映射:
<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>
我有一个函数尝试使用此地图在文档中查找图像:
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);
}
}
它无法找到图像。
Could not find image using img [usemap=\#map_books]
我已经逃脱了,elemId
因为它以哈希开头并尝试了选择器的变体。
$("img [usemap$=" + elemId.substring(1) + "]")
$("img").find("[usemap=\\" + elemId + "]")
也找不到图。有任何想法吗?