1
我試圖找出一個CONTENTEDITABLE格,看起來像這樣內的光標的直接父(段落元素):獲取keydown事件的父元素,jQuery的
<div id=base>
<div ce='1' contenteditable='true'>
<p id='unique'>Paragraph one</p>
<p>Paragraph two</p>
</div>
</div>
如果我綁定。點擊事件的'ce'div,則event.currentTarget被報告爲發生點擊的段落。但跟蹤光標我需要使用.keydown事件
$('#base').on({
keydown: function(event) {
myLog(' nodeName: '+event.currentTarget.nodeName);
},
// With the following selector the event is triggered with the cursor
// anywhere in 'ce', and .currentTarget is the 'ce' div.
}, '[ce]');
// With this selector the event is never triggered regardless of cursor position
}, '#unique');
爲什麼沒有被觸發的情況下,我如何能實現我的目標是什麼?