[英]HTML DOM Area Object / Javascript
試圖創建此地圖區域,但是它不起作用。 有人知道解決方案嗎? 謝謝
的HTML:
<html>
<body>
<table border="1">
<tr>
<td>logo</td>
<td>description</td>
</tr>
<tr>
<td colspan="2">
<map id ="first" name="Homepage"></map>
<script src="appendChild.js"></script>
</td>
</tr>
</table>
</body>
</html>
js:
var start= document.createElement("AREA");
start.setAttribute("href", "Homepage.html");
start.setAttribute("src" , "Homepage.jpg");
start.setAttribute("shape", "rect");
start.setAttribute("coords", "18,131,113,140");
document.getElementById("first").appendChild(start);
您必須創建一個usemap
屬性設置為#
+ [ <map>
元素的name
值]的元素(通常為<img>
)。 對於您的情況,您需要具有<img src="Homepage.jpg" usemap="#Homepage" />
。
編輯:您也可以動態添加<img>
。
var start = document.createElement("AREA"), image = document.createElement("IMG"); start.setAttribute("href", "Homepage.html"); start.setAttribute("shape", "rect"); start.setAttribute("coords", "18,131,113,140"); image.setAttribute("src", "//placekitten.com/221/221"); image.setAttribute("usemap", "#Homepage"); document.getElementById("first").appendChild(image); document.getElementById("first").appendChild(start);
<table border="1"> <tr> <td>logo</td> <td>description</td> </tr> <tr> <td colspan="2"> <map id="first" name="Homepage"></map> <script src="appendChild.js"></script> </td> </tr> </table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.