How can I blur a div where contentEditable=true?

前端 未结 4 879
逝去的感伤
逝去的感伤 2021-01-11 08:57

How can I blur/focusout a div where contentEditable=true? I have attempted $(elm).blur() and $(elm).attr(\'contentEditable\', false);

4条回答
  •  走了就别回头了
    2021-01-11 09:44

    I would add another solution that is based on Omnicon's answer which is correct BTW. I have forked his fiddle and updated it.

    The trick is to remove all ranges after calling blur:

    $(".editable").blur();
    window.getSelection().removeAllRanges();
    

提交回复
热议问题