2

我如何使这项工作:

<div onclick="alert('You clicked me!')" style="background:lightblue;display:inline-block;padding:20px">
    <textarea rows="5" cols="50">You can click and select text here normally, but I don't register mouse events from the DIV behind me!</textarea>
    <div id="inner" style="background:lightgreen">Same here. I want my own mouse events - not the ones from #inner.</div>
</div>

谢谢!

4

1 回答 1

3

我猜你想要这个:

<div onclick="if (event.target === this) alert('You clicked me!')">

现场演示:http: //jsfiddle.net/UZtag/1/

因此,如果单击 TEXTAREA 或 #inner DIV,则不会弹出警报,但仅当直接单击外部 DIV 时才会弹出警报。

于 2012-07-29T18:53:12.787 回答