aaaa
<input onclick="alert(document.selection.createRange().text)" type=button value=get>

解决方案 »

  1.   

    IE5.5 以上支持:
    <html>
    <head>
    <script language="JavaScript">
    document.onselectionchange = doChange;
    function doChange(){
     if(document.selection.type=="None") return;
     t = document.selection.createRangeCollection();
     sel.value="";
     for(i=0; i<t.length; i++)
      sel.value += t(i).text;
    }
    </script>
    </head>
    <body>
    To retrieve a text range object, apply the createTextRange method to a body, BUTTON, or TEXTAREA element or an INPUT element that has TYPE text. 
    <button>INPUT element</button>Modify the extent of the text range by moving its start and end positions with methods such as move, moveToElementText, and findText. Within the text range, you can retrieve and modify plain text or HTML text. These forms of text are identical except that HTML text includes HTML tags, and plain text does not. This object is available in script as of Microsoft?Internet Explorer 
    <textarea id=sel cols=80 rows=20></textarea>
    </body>
    </html>
      

  2.   

    哦这样子啊,没有getSelection()方法吗?那creatRange()是什么意思?
      

  3.   

    document.onselectionchange吗?IE5.5以上包不包括5.5呢?
    那document.selection.createRangeCollection()又是什么意思?跟上面creatRange()有什么关系吗?
      

  4.   

    document.selection.createRange().text;<html>
    <head>
    <script language="JavaScript">
    document.onselectionchange = doChange;
    function doChange(){
      sel.value = document.selection.createRange().text;
    }
    </script>
    </head>
    <body>
    To retrieve a text range object, apply the createTextRange method to a body, BUTTON, or TEXTAREA element or an INPUT element that has TYPE text. 
    <button>INPUT element</button>Modify the extent of the text range by moving its start and end positions with methods such as move, moveToElementText, and findText. Within the text range, you can retrieve and modify plain text or HTML text. These forms of text are identical except that HTML text includes HTML tags, and plain text does not. This object is available in script as of Microsoft?Internet Explorer 
    <textarea id=sel cols=80 rows=20></textarea>
    </body>
    </html>