Why doesn't the document.execCommand work when I click on a div?

前端 未结 3 608
小鲜肉
小鲜肉 2020-12-16 04:19

Both the button and the div have the same \'onclick\' code, yet the execCommand only seems to work on the button. Is there any way I can make it work when pressing the div?<

相关标签:
3条回答
  • 2020-12-16 05:00

    For Firefox, it's necessary to set contenteditable = true before execCommand.

    For IE it is not necessary.

    0 讨论(0)
  • 2020-12-16 05:03

    See this fiddle :- http://jsfiddle.net/ZzL8y/4/
    This is not the complete answer but these links might help you:-

    1> set execcommand just for a div

    2> select all text in contenteditable div when it focus/click

    0 讨论(0)
  • 2020-12-16 05:21

    You need to prevent the mousedown event on your div because it steals the focus:

    Updated fiddle

    0 讨论(0)
提交回复
热议问题