触发图像地图区域的点击行为

发布于 2024-09-04 15:20:32 字数 358 浏览 1 评论 0原文

我设置了一个图像映射,并且图像映射中的每个区域都定义了一个 href。区域上的 href 包含我的应用程序中其他页面的 url。我生成一个小列表(ul,li),其中列出了区域标记的名称属性。我希望动态生成的 ul/lis 模仿区域标记的点击行为。为此,我设置了以下 jquery -

 $('li').click(function(e){
       $('area[name='+$(this).html()+']').trigger('click');
 });

但以上仅在 ie6+ 中运行良好。 ff 不会触发点击事件。我也尝试了 click() 变体但无济于事。

期待一些帮助。

谢谢 :)

I have a image map set up and each area in the image map has a href defined. the href on area contains urls to other pages in my application. i generate a small list (ul, li) which lists down the name attribute of the area tag. i want the dynamically generated ul/lis to imitate click behaviour of area tag. for this, i have the following jquery set up -

 $('li').click(function(e){
       $('area[name='+$(this).html()+']').trigger('click');
 });

but the above works well only in ie6+. ff does not fire the click event. i also tried the click() variant but to no avail.

looking forward for some help.

Thanks :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡尘雨 2024-09-11 15:20:32

在 FireFox 的情况下,触发 click 事件会触发绑定到该元素(在本例中为 li 元素)的 onClick 处理程序,但实际上并不跟随该链接。据我了解,您希望点击跟随与 li 元素关联的区域的链接

尝试这个,这会获取关联区域的 href 属性并使用 javascript 进行重定向

$('li').click(function(e){
    var $area = $('area[name='+$(this).html()+']');
    var url = $area.attr("href");
    document.location.href = url;
});

In FireFox' case, triggering the click event fires the onClick handlers bound to the element (in this case your li elements), but does not actually follow the link. As I understand it, you want the clicks to follow the link of the area associated with the li element

Try this, this fetches the href attribute of the associated area and redirects using javascript

$('li').click(function(e){
    var $area = $('area[name='+$(this).html()+']');
    var url = $area.attr("href");
    document.location.href = url;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文