Range——插入对象insertNode

来源:互联网 发布:如何设计软件 编辑:程序博客网 时间:2024/06/06 18:23
<!DOCTYPE html>  <html>  <head>      <meta charset="utf-8" />      <title></title>  </head>  <body>  请先选择文字,再点击按钮<br><div id="d1" style="background-color:red">“嘻嘻”,雪儿忍不住笑了,自言自语道,“百草闲居,百草·······哇——”雪儿叫道,这个“哇”连拐了三个弯儿,“昨天晚上,我梦见了,梦见了和现在的一样的情景,我还像一只会发光的水母呢,我看见了会开桂花的梧桐树,我和哥哥的小时候,</div><input type="button" value="移动按钮" onmouseup="onc()" id="b"></body>               <script>  function onc(){var b=document.getElementById("b");var s=document.getSelection();//获取页面的选择区域if(s.rangeCount>0){var r=s.getRangeAt(0);//获取页面选择区域的第一个位子r.insertNode(b);//第一个位子前插入button}}</script>  </html>  

0 0