我可以在imagemap区域元素上有一个onclick事件 [英] can i have an onclick event on a imagemap area element

查看:704
本文介绍了我可以在imagemap区域元素上有一个onclick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在区域元素上放置一个onclick事件。这是我的设置:

I would like to put an onclick event on an area element. Here is my setup:

<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>

我尝试了两种不同的方式来进行onclick事件。首先我试过这个:

I have tried 2 different ways to have an onclick event. Firstly i tried this:

$(".blue").click( function(event){
    alert('test');
});

我也试过这个:

function myFunction() {
    alert('test');
}

上述两项工作均无效。区域元素是否支持上述内容,或者它们是否只支持href?

Neither of the above work. Do area elements support the above, or do they only support having a href?

提前致谢!

推荐答案

注意:


  1. 属性href是强制性的,没有它,区域标签就是什么都没有!

  1. Attribute href is obligatory, without it the area-tag does nothing!

要添加点击事件,您需要阻止默认href。

To add a click event, you'll need to block default href.






您的代码应如下所示:


Your code should start as follows:

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

此处的实例。

这篇关于我可以在imagemap区域元素上有一个onclick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆