onkeyup, onkeydown events not firing for SPAN element

后端 未结 3 2021
陌清茗
陌清茗 2020-12-20 05:11

I\'ve defined the following two span elements: 1) element inside a contenteditable div. 2) contenteditable element.

So far, I can\'t get the onkey events to fire

3条回答
  •  忘掉有多难
    2020-12-20 06:05

    I had the same problem and it seems to work if you put your editable span inside another non-editable span :

    div contents... Hello

    You will be able to catch keydown/keyup events both on the editor div AND in your span1.

    EDIT: you need the inner span to have the focus to catch keydown events coming from it. Use the DOM method .focus() to do so.

提交回复
热议问题