+ -
当前位置:首页 → 问答吧 → 怎么选中鼠标划中的内容

怎么选中鼠标划中的内容

时间:2009-11-18

来源:互联网

rt 我要选中用鼠标划中的划中的词, 怎么用jquery实现呢 ?  请问

作者: coolesting   发布时间: 2009-11-18

复制代码
  1. <html>
  2. <head>
  3. <script>
  4. var isNav = (navigator.appName.indexOf("Netscape") !=-1);
  5. function showSelection(){
  6.     if (window.getSelection) {
  7.         alert(window.getSelection());
  8.         document.forms[0].selectedText.value=window.getSelection();
  9.     }
  10.     else if(document.getSelection) {
  11.         alert(document.getSelection());
  12.         document.forms[0].selectedText.value=document.getSelection();
  13.     }
  14.     else if(document.selection) {
  15.         alert(document.selection.createRange().text);
  16.         document.forms[0].selectedText.value=document.selection.createRange().text;
  17.     }
  18. }
  19. if(isNav){
  20.     document.captureEvents(Event.MOUSEUP);
  21. }
  22. document.onmouseup = showSelection;
  23. </script>
  24. </head>
  25. <body>
  26.     <p>
  27.         这些都是用来测试的文本,您可以用鼠标来选中,然后试一试选择文本后产生的结构。
  28.     </p>
  29.     <form name="dataholder">
  30.         <textarea name="selectedText" rows = 3 cols=40 wrap="virtusl"></textarea>
  31.     </form>
  32. </body>
  33. </html>

作者: huaganshang   发布时间: 2009-11-19

  谢谢, 那天刚发完帖, 我就解决了这个问题, 大至就是和你写的一样,


但是我不能用jquery实现,都是js

作者: coolesting   发布时间: 2009-11-19

支持一个·················学习了····

作者: thecorsair   发布时间: 2009-12-03

相关阅读 更多