Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我可以在imagemap区域元素上有onclick事件吗?_Javascript_Jquery_Onclick_Area_Imagemap - Fatal编程技术网

Javascript 我可以在imagemap区域元素上有onclick事件吗?

Javascript 我可以在imagemap区域元素上有onclick事件吗?,javascript,jquery,onclick,area,imagemap,Javascript,Jquery,Onclick,Area,Imagemap,我想在区域元素上放置onclick事件。以下是我的设置: <img id="image" src="wheel.png" width="2795" height="2795" usemap="#Map" > <map name="Map"> <area class="blue" onclick="myF

我想在区域元素上放置onclick事件。以下是我的设置:

<img id="image" src="wheel.png" width="2795" height="2795" usemap="#Map" >
    <map name="Map">
    <area class="blue" onclick="myFunction()" shape="poly" coords="2318,480,1510,1284" href="#">
</map>
我也试过:

$(".blue").click( function(event){
    alert('test');
});
function myFunction() {
    alert('test');
}
以上两项都不起作用。区域元素是否支持上述功能,还是只支持a href?

试试:

<img  src="wheel.png" width="2795" height="2795" alt="Weels" usemap="#map">

<map name="map">
 <area shape="poly" coords="2318,480,1510,1284" alt="otherThing" href="anotherFile">
</map>

您不想在区域、文档中添加
onClick
事件:

标记定义了图像映射内的区域(图像映射是具有可单击区域的图像)

编辑:你的坐标有点奇怪,因为它应该是每个顶点的对(所以现在,你的多边形是一条线)

试试:

<img  src="wheel.png" width="2795" height="2795" alt="Weels" usemap="#map">

<map name="map">
 <area shape="poly" coords="2318,480,1510,1284" alt="otherThing" href="anotherFile">
</map>

您不想在区域、文档中添加
onClick
事件:

标记定义了图像映射内的区域(图像映射是具有可单击区域的图像)

编辑:你的坐标有点奇怪,因为它应该是每个顶点的对(所以现在,你的多边形是一条线)

注意:

  • 属性href是必需的,如果没有它,区域标记将不会起任何作用

  • 要添加单击事件,您需要阻止默认href


  • 您的代码应按如下方式开始:

    $(".blue").on("click", function(e){
        e.preventDefault();
        /*
           your code here
        */
    });
    
    请注意:

  • 属性href是必需的,如果没有它,区域标记将不会起任何作用

  • 要添加单击事件,您需要阻止默认href


  • 您的代码应按如下方式开始:

    $(".blue").on("click", function(e){
        e.preventDefault();
        /*
           your code here
        */
    });
    

    根据您的评论,您只需要:

    $("#image").click( function(){
     alert("clicked");
    //your code here
    });
    

    演示:


    根据您的评论,您只需要:

    $("#image").click( function(){
     alert("clicked");
    //your code here
    });
    

    演示:


    问题出在形状上。代码已将“形状”设置为“多边形”,但“坐标”属性中只有4个点。您需要将“形状”改为“矩形”

    如下设置shape=“rect”:


    问题出在形状上。代码已将“形状”设置为“多边形”,但“坐标”属性中只有4个点。您需要将“形状”改为“矩形”

    如下设置shape=“rect”:


    我是通过@TimorEranAV找到这个问题的 被标记为复制品但我想他期望的是

    <html>
    <head>
     <title> Program - Image Map</title>
    </head>
    <body>
    
    
     <img src="new.png" width="145" height="126" alt="Planets" usemap="#planetmap">
    
    <map name="planetmap">
      <area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun" title = "Sun">
      <area shape="rect" coords="82,0,100,126" href="mercur.htm" alt="Mercury" title = "Mercury">
    
    </map>
    
    </body>
    </html>
    
    
    程序图像映射
    

    在这里,title标签提供了向图像地图添加悬停文本(提示)的机会。

    我在@TimorEranAV发现了这个问题 被标记为复制品但我想他期望的是

    <html>
    <head>
     <title> Program - Image Map</title>
    </head>
    <body>
    
    
     <img src="new.png" width="145" height="126" alt="Planets" usemap="#planetmap">
    
    <map name="planetmap">
      <area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun" title = "Sun">
      <area shape="rect" coords="82,0,100,126" href="mercur.htm" alt="Mercury" title = "Mercury">
    
    </map>
    
    </body>
    </html>
    
    
    程序图像映射
    

    在这里,title标签提供了向图像映射添加悬停文本(提示)的机会。

    为所有要侦听的元素使用一个类,并可选地为行为使用一个属性:

    <map name="primary">
      <area shape="circle" coords="75,75,75" class="popable" data-text="left circle text">
      <area shape="circle" coords="275,75,75" class="popable" data-text="right circle text">
    </map>
    <img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">
    <div class='popup hidden'></div>
    

    演示:

    为要侦听的所有元素使用一个类,并可选地为行为使用一个属性:

    <map name="primary">
      <area shape="circle" coords="75,75,75" class="popable" data-text="left circle text">
      <area shape="circle" coords="275,75,75" class="popable" data-text="right circle text">
    </map>
    <img usemap="#primary" src="http://placehold.it/350x150" alt="350 x 150 pic">
    <div class='popup hidden'></div>
    
    演示:

    这是一个简单的演示:

    这是一个简单的例子:



    需要获取哪个值?另外,您在
    “231848015101284”上还有一个额外的报价“
    ?您尝试单击的区域不可单击!:)这是默认行为吗?@PedroLobito我需要在点击时调用一个javascript函数,这个额外的引号是打字错误,就这样?!您不需要用户单击的坐标?您需要获取哪个值?另外,您在
    “231848015101284”上还有一个额外的报价“
    ?您尝试单击的区域不可单击!:)这是默认行为吗?@PedroLobito我需要在点击时调用一个javascript函数,这个额外的引号是打字错误,就这样?!您不需要用户单击的坐标,但我想调用一些javascript onclick。这是不可能实现的吗?当然,只需在要单击的区域添加一个id,并使用
    $(“#id”)。在(“单击”,函数(e){//DoSTG})$(“#id”)。在(“单击”,函数(e){//DoSTG})这是一个很好的答案。。。但我可以知道我需要更改什么以在单击时显示图像吗?请参考HTML5中的这个问题,href可能会被省略:这是一个很好的答案。。。但我可以知道我需要更改什么以在单击时显示图像吗?请参考HTML 5中的这个问题,href可能会被省略:您添加了一个代码段,但没有内容,因此没有“要看”的内容被呈现,也许您可以修改HTML代码以准确地查看运行代码段您所做的事情您添加了一个代码段,但没有内容,因此没有“要看”的内容被呈现,也许你可以修改html代码来准确地查看你所做的运行代码段这实际上回答了OP的问题,不需要jquery。这实际上回答了OP的问题,不需要jquery。