//把光标移到末尾
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();
}
}
本文介绍了一种在不同浏览器中将光标定位到文本末尾的方法。通过使用JavaScript,该方法解决了跨浏览器兼容性问题,并确保了光标能够准确地定位到最后一个字符之后。

845

被折叠的 条评论
为什么被折叠?



