我可以在 imagemap 区域元素上设置 onclick 事件吗? [英] Can I have an onclick event on a imagemap area element?

查看:23
本文介绍了我可以在 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>

我尝试了 2 种不同的方式来设置 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 是强制性的,没有它,area-tag 什么都做不了!

  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天全站免登陆