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>