我如何做这项工作:
<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>
谢谢!
答案 0 :(得分:3)
我猜你想要这个:
<div onclick="if (event.target === this) alert('You clicked me!')">
现场演示: http://jsfiddle.net/UZtag/1/
因此,如果单击TEXTAREA或#inner DIV,则警报会不弹出,但仅在直接单击外部DIV时才会弹出。