ContentEditable focus in Chrome/Safari

后端 未结 2 2041
醉酒成梦
醉酒成梦 2021-01-12 14:25

I have a contenteditable div which needs to be focussed at pageload (place cursor at the first line).

document.getElementById(\"editor\").focus() works

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-12 14:31

    I was able to add focus to a DIV by calling the focus() method chained to the attr() method

    $el.attr('contenteditable', "true").focus()
    

提交回复
热议问题