|
@@ -148,21 +148,26 @@ export default {
|
|
|
},
|
|
|
moveToEnd() {
|
|
|
const editableDiv = this.$refs.myEditBox;
|
|
|
- if(editableDiv.lastChild) {
|
|
|
- const range = document.createRange();
|
|
|
- const selection = window.getSelection();
|
|
|
- // 将范围设置为从文本末尾到文本末尾(实际上是一个空范围,但用于设置光标位置)
|
|
|
- range.setStart(editableDiv.lastChild, editableDiv.lastChild.textContent.length);
|
|
|
- range.setEnd(editableDiv.lastChild, editableDiv.lastChild.textContent.length);
|
|
|
-
|
|
|
- // 应用选择范围
|
|
|
- selection.removeAllRanges();
|
|
|
- selection.addRange(range);
|
|
|
+ try{
|
|
|
+ if(editableDiv.lastChild) {
|
|
|
+ const range = document.createRange();
|
|
|
+ const selection = window.getSelection();
|
|
|
+ // 将范围设置为从文本末尾到文本末尾(实际上是一个空范围,但用于设置光标位置)
|
|
|
+ range.setStart(editableDiv.lastChild, editableDiv.lastChild.textContent.length);
|
|
|
+ range.setEnd(editableDiv.lastChild, editableDiv.lastChild.textContent.length);
|
|
|
+
|
|
|
+ // 应用选择范围
|
|
|
+ selection.removeAllRanges();
|
|
|
+ selection.addRange(range);
|
|
|
+ }
|
|
|
+ }catch{
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 确保光标可见(在某些浏览器中可能需要)
|
|
|
- editableDiv.focus();
|
|
|
+ editableDiv.focus();
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
|
|
|
clickBtn(method){
|