How to preserve text selection when opening a jQuery dialog

▼魔方 西西 提交于 2019-12-02 02:40:42
Paul Tarjan

The jQuery dialog will take the user's focus ( you should see one of the buttons selected on the dialog ). Browsers only have 1 focus so you lose whatever they had selected.

You should just retrieve the start and end positions of the user's selection before you do the dialog, and then reselected it after the dialog goes away.

I don't have any example code for getting and setting user's selection, but a web search should find you some.

Something like :

$("dialog").focus(function() {
  // save the selection
}).blur(function() {
  // set the text selection
});

[edited (Nickolay): see Keep text selection when focus changes for more code]

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!