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 に答える