码迷,mamicode.com
首页 > Web开发 > 详细

web 获取 文本选中

时间:2019-09-20 19:18:23      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:func   eal   apple   cti   ret   win   gets   pre   col   

js 获取 文本选中

 1 <html>
 2 <script>
 3   // 取消文本选中
 4    var clearSlct= "getSelection" in window ? function(){
 5     window.getSelection().removeAllRanges();
 6   } : function(){
 7     document.selection.empty();
 8   };
 9   function getSelectionText() {
10     if(window.getSelection) {
11       return window.getSelection().toString();
12     } else if(document.selection && document.selection.createRange) {
13       return document.selection.createRange().text;
14     }
15     return ‘‘;
16   }
17 
18 </script>
19 <body>
20 <p>据外媒报道,苹果移动支付Apple Pay推出后被寄予厚望,而且花旗银行和大通银行这样的金融界巨头就已经是Apple Pay的重
21 要合作伙伴了。对此,苹果表示Apple Pay目前已经支持全美90%的信用卡。
22 </p>
23 <input type="button" value="弹出选择文字" onclick="window.alert(getSelectionText());clearSlct();">
24 </body>
25 </html>

 

web 获取 文本选中

标签:func   eal   apple   cti   ret   win   gets   pre   col   

原文地址:https://www.cnblogs.com/ljyyjj/p/11558646.html

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