当前位置: 代码迷 >> JavaScript >> js失去选中的文字
  详细解决方案

js失去选中的文字

热度:95   发布时间:2012-07-16 15:44:59.0
js得到选中的文字
  <script type="text/javascript">
    function getWords(){  
    var text;  
    if(navigator.appName=="Microsoft Internet Explorer"){  
       text=document.selection.createRange().text;  
    }else{  
        text=window.getSelection();  
  }  
    alert(text);
}  
   
    </script>
  </head>
 
  <body>
  <input type="button" value="获取" onclick="getWords()"/>
<br/>  
<textarea rows="15" id="txt" cols="100"></textarea>  
</body>  
</html>
  相关解决方案