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