Commit e7fefc6d7803cdc2f258a41dbf7e207ba1bca603

Authored by bichao.dong
1 parent 1ab4ca37

reset range

Showing 1 changed file with 7 additions and 2 deletions
editer.html
... ... @@ -70,9 +70,10 @@
70 70 <script src="js/javascript/common/jquery.min.js"></script>
71 71 <script>
72 72 $(function() {
73   - var range;
  73 + var selection, range;
74 74 $('.editer').on('click', function(){
75   - range = window.getSelection().getRangeAt(0);//找到焦点位置
  75 + selection = window.getSelection();
  76 + range = selection.getRangeAt(0);//找到焦点位置
76 77 });
77 78 $('#upload_btn').on('change', function(target) {
78 79 target = $(this);
... ... @@ -118,6 +119,10 @@
118 119 img.src = base64;
119 120 if(range){
120 121 range.insertNode(img);//在焦点插入节点
  122 + range.setEndAfter(img);
  123 + range.setStartAfter(img);
  124 + selection.removeAllRanges();
  125 + selection.addRange(range);
121 126 }else{
122 127 $('.editer').append($(img));
123 128 }
... ...