ZhengXingchi / ZhengXingchi.github.io

Apache License 2.0
0 stars 0 forks source link

富文本框 #84

Open ZhengXingchi opened 4 years ago

ZhengXingchi commented 4 years ago

参考文献

react-contenteditable React组件实现一个内容可编辑的div

仅用1行核心JS代码实现一个轻量级富文本编辑器 | 拓跋的前端客栈

ZhengXingchi commented 4 years ago

pell

the simplest and smallest WYSIWYG text editor for web, with no dependencies 一个短小精悍没有任何依赖的浏览器富文本编辑器 readme中有各个富文本编辑器的对比 jaredreich/pell的github地址

相关解析简单实现JavaScript 富文本编辑器的方法

ZhengXingchi commented 4 years ago

关于焦点

这篇文章很有启发意义javascript – focus()在边缘浏览器中不起作用

ZhengXingchi commented 4 years ago

关于评论框带微博表情

(仿多说留言、评论框,带微博表情) 仿多说留言、评论框,带微博表情。 查看演示

ZhengXingchi commented 4 years ago

楼中楼的评论系统

原贴 如何实现一个楼中楼的评论系统 如何实现一个楼中楼的评论系统

ZhengXingchi commented 4 years ago

在textarea指定位置插入内容

在 textarea中指定位置插入内容

ZhengXingchi commented 4 years ago

移动光标到末尾

/把光标移到末尾
msgTextLastPos(obj) {
// 解决浏览器的兼容问题,做如下条件判断
if (window.getSelection) {
obj.focus();
let range = window.getSelection();
range.selectAllChildren(obj);
range.collapseToEnd();//光标移至最后
}
else if (document.selection) {
let range = document.selection.createRange();
range.moveToElementText(obj);
range.collapse(false);//光标移至最后
range.select();
}
}

参考自富文本中 移动光标到末尾

本来想参考 focus到文本框尾部上面趁你还年轻的答案,但是没有效果。

const el = document.getElementById('richTextEditor');
const range = document.createRange();
const sel = window.getSelection();
console.log(document.activeElement);
const tailIndex = el.childNodes.length;
const tailNode = el.childNodes[tailIndex - 1];
range.setStart(tailNode, tailNode.length);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);

但是对于