码迷,mamicode.com
首页 > Windows程序 > 详细

html 富文本编辑器相关--常用selection range api

时间:2017-04-13 18:36:29      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:sed   技术   lap   closed   富文本   htm   tor   容器   close   

 

selection.setPosition(container,5);  设置光标位置--到尾端
selection.setPosition(container,0);  设置光标位置--到首端

container 为 编辑容器dom,5 为编辑器子元素的长度,
技术分享
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        #app{
            width:300px;
            height:100px;
            border: 1px solid red;
        }
        img{
            width: 20px;

        }
    </style>
</head>
<body>
<!--<div contenteditable="true" id="app">
    <img src="a.jpg" alt=""> 123

</div>-->
<div contenteditable="true" id="app">
   11<img src="a.jpg" alt=""><img src="a.jpg" alt=""> 00 <span class="sp">123</span>

</div>

</body>
<script>


    let app = document.querySelector(#app);
    app.focus();
    let selection = getSelection();
    selection.setPosition(app,5);


</script>
</html>
View Code

 

html 富文本编辑器相关--常用selection range api

标签:sed   技术   lap   closed   富文本   htm   tor   容器   close   

原文地址:http://www.cnblogs.com/WhiteHorseIsNotHorse/p/6705396.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!