简体   繁体   English

HTML DOM区域对象/ Javascript

[英]HTML DOM Area Object / Javascript

Tried to create this map area, but it doesn't work. 试图创建此地图区域,但是它不起作用。 Does someone know the solution? 有人知道解决方案吗? Thanks 谢谢

html: 的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: 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);

You have to create an element (usually an <img> ) with the usemap attribute set to # + [the <map> element's name value]. 您必须创建一个usemap属性设置为# + [ <map>元素的name值]的元素(通常为<img> )。 In your case, you'd need to have an <img src="Homepage.jpg" usemap="#Homepage" /> . 对于您的情况,您需要具有<img src="Homepage.jpg" usemap="#Homepage" />

EDIT: You can add that <img> dynamically, too. 编辑:您也可以动态添加<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM