时间:2021-07-01 10:21:17 帮助过:26人阅读
5.createRange()方法创建range对象;
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>range对象</title> </head> <body> selection对象和range对象 <input type="button" value="点击" onclick="use()"> <div id="rangeDiv"></div> <script> function use() { var html; rangeDiv=document.getElementById("rangeDiv"); selection=document.getSelection(); if(selection.rangeCount>0){ html="您选择了"+selection.rangeCount+"段内容<br/>" ; for(var i=0;i<selection.rangeCount;i++){ var range=selection.getRangeAt(i); html+="第"+(i+1)+"段内容为:"+range+"<br/>"; } rangeDiv.innerHTML=html; } } </script> </body> </html>
更多API之range对象相关文章请关注PHP中文网!