开发者

Is there a way to trigger the onclick of any item that is behind another item in JavaScript?

开发者 https://www.devze.com 2023-02-04 17:32 出处:网络
Basically, I am using different div to highlight sections of text.Basically, I would like to know if the user clicked on that highlighted selection.

Basically, I am using different div to highlight sections of text. Basically, I would like to know if the user clicked on that highlighted selection.

However. the highlighting div is behind the text, so the onclick method for the div does not seem to be called. It there some trick to get around this?


<!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 t开发者_JAVA百科est!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>


You could do this way:

on the highlight div you could set

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

you have to set opacity if you want to show the highlight div and in the back the text

example here: http://jsfiddle.net/steweb/Cqvve/

0

精彩评论

暂无评论...
验证码 换一张
取 消