- function select(el){
- var el = $(el)[0];
- if (window.getSelection) {//ie11 10 9 ff safari
- el.focus(); //解决ff不获取焦点无法定位问题
- var selection = window.getSelection();//创建range
- selection.selectAllChildren(el);//range 选择obj下所有子内容
- selection.collapseToEnd();//光标移至最后
- // selection.collapse(el, 1);
- }
- else if (document.selection) {//ie10 9 8 7 6 5
- var range = document.selection.createRange();//创建选择对象
- range.moveToElementText(el);//range定位到obj
- range.collapse(false);//光标移至最后
- range.select();
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/1802201614552.html
来源: http://www.codesnippet.cn/detail/1802201614552.html