contenteditable div: IE8 not happy with backspace remove of HTML element

前端 未结 2 1822
梦如初夏
梦如初夏 2021-02-06 06:59

I am making use of a contenteditable div in combination with the rangy Javascript library to insert HTML at the cursor position.

End of the day the contents of the div c

2条回答
  •  梦毁少年i
    2021-02-06 07:39

    I made a jsfiddle with a quick sample of how to look at the range of the selection and use the previousSibling property of the startContainer to find the button: jsfiddle

    Put the cursor in aaa and it will show the button is prev sibling. put it in ccc and bbb will show.

    So with this you could handle the keydown event of the div, check if key is backspace + previousSibling is your button, and remove it with jQuery.

    previousSibling is null if it is a textnode though, just FYI.

提交回复
热议问题