如何将点击事件从一个div传递到另一个div? [英] How to pass click events from one div to another?

查看:821
本文介绍了如何将点击事件从一个div传递到另一个div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种方法,将点击事件从顶部的div传递到其下面的div(并忽略较高div上的点击). 有一种模拟点击事件并将其传递给另一个div的已知方法,但这不是自然的行为,也是最不需要的选项.

I need to find a way to pass click events from a div on top to the div below it (and ignore the clicks on the higher div). There is a known way of simulating the click event and passing it to the other div, but this is not a natural behavior and the least wanted option.

事件冒泡似乎无济于事,因为顶部的div不包含在下面的区域中..

It seems that event bubbling will not help here since the div on the top is not contained in the one below..

有什么主意吗?

这是一个jsfiddle示例:

here is a jsfiddle example:

http://jsfiddle.net/QKjUx/

如果删除覆盖" div,则可以单击任意一个元素.当它在那里时,您不能.可以将事件传递到下面的div,但是位置很重要-可能有一个链接,我希望用户可以单击该链接.

If you remove the "overlay" div, you can click on either of the elements. While it's there, you cannot. It is possible to pass the event to the div below, however, the position is important - there can be a link which I want the user to be able to click on.

推荐答案

将此CSS属性添加到叠加层div:

add this css property to the overlay div:

   pointer-events: none;

您可以在以下网址了解更多信息: http://robertnyman.com/2010/03/22/css-pointer-events-to-allow-clicks-on-underlying-elements/

You can read more about it at: http://robertnyman.com/2010/03/22/css-pointer-events-to-allow-clicks-on-underlying-elements/

这篇关于如何将点击事件从一个div传递到另一个div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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