javascript - 有没有办法触发 JavaScript 中另一个元素后面的任何元素的点击?

标签 javascript html css dom-events

基本上,我使用不同的 div 来突出显示文本部分。基本上,我想知道用户是否点击了突出显示的选择。

但是。突出显示的 div 在文本后面,因此似乎没有调用 div 的 onclick 方法。有什么技巧可以解决这个问题吗?


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >
    </head>
    <body>
        <div style="position: relative">
            <div style="width:200px;height:200px;background-color: seagreen; position: absolute; left: 40px; top: 40px; z-index: -1" onclick="alert('called?')"></div>
            <pre >
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!
This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!This is a test!

            </pre>
        </div>
    </body>
</html>

最佳答案

你可以这样做:

在你可以设置的高亮div上

z-index:1;
opacity:0.2; /* from 0 to 1*/
filter:alpha(opacity=20); /* IE opacity fix */

如果你想显示高亮div和后面的文本,你必须设置不透明度

此处示例:http://jsfiddle.net/steweb/Cqvve/

关于javascript - 有没有办法触发 JavaScript 中另一个元素后面的任何元素的点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4701269/

相关文章:

javascript - React props : Should I pass the object or its properties? 有多大区别?

html - 此结构的 CSS

javascript - 向 DOM 元素添加属性

css - 中心 ul Sprite 导航

javascript - picturefill.js 问题与 z-index

javascript - 如何重新排序异步函数的执行顺序?

html - 导航链接不会变回原来的颜色

html - 如何删除面板底部多余的空白区域

html - Bootstrap 3 图像不会填满轮播,卡在左边

javascript - 电子表格中的 Google Apps 脚本错误