码迷,mamicode.com
首页 > 其他好文 > 详细

将鼠标移到文本最后

时间:2016-11-19 20:11:28      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:support   focus   文本   pre   style   toe   else   text   this   

 1 //将鼠标移到文本最后
 2 function set_focus(el) {
 3     el.focus();
 4     if (el instanceof jQuery) el = el[0];
 5     //el=el[0];  //jquery 对象转dom对象
 6     if ($.support.msie) {
 7         var range = document.selection.createRange();
 8         this.last = range;
 9         range.moveToElementText(el);
10         range.select();
11         document.selection.empty(); //取消选中
12     }
13     else {
14         var range = document.createRange();
15         range.selectNodeContents(el);
16         range.collapse(false);
17         var sel = window.getSelection();//适用于firefox和safari
18         sel.removeAllRanges();//取消选中
19         sel.addRange(range);
20     }
21 }

 

将鼠标移到文本最后

标签:support   focus   文本   pre   style   toe   else   text   this   

原文地址:http://www.cnblogs.com/sunnie-cc/p/6081090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!