Make programmatic range selection visible to the user?

99封情书 提交于 2019-12-08 00:21:37

问题


How can I make a programmatical page selection visible to the user, as if it was selected by the user?

var range = document.createRange();
var startPar = [some node];
var endLi = [some other node];
range.setStart(startPar,13);
range.setEnd(endLi,17);

Thank you.


回答1:


Use:

window.getSelection().addRange(range);


来源:https://stackoverflow.com/questions/1426634/make-programmatic-range-selection-visible-to-the-user

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