问题是,如果我关注childOfroot元素并按下一个键,触发的元素是它的父元素,但它应该是它自己。
function test(event, element) {
console.log($(element).attr('id'))
}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span id="root" contenteditable="true" onkeyup="test(event, this)">
This is changable
<span contenteditable="true" onkeyup="test(event, this)" id="childOfroot"> | including this</span>
</span>
请在此处查看演示:https://jsfiddle.net/s36L8bpj/
发布于 2020-05-06 01:41:53
对于那些有同样问题的人来说,如果父元素有contenteditable="true",显然你不能发送元素own事件。
所以我把我的结构改成了下面:
<span id="root" contenteditable="false" >
<span contenteditable="true" onkeyup="test(event, this)" id="childOfroot0">This is changable
<span contenteditable="true" onkeyup="test(event, this)" id="childOfroot1"> | including this</span>
</span>愿平安降临于你:)
https://stackoverflow.com/questions/61597825
复制相似问题