解决方案 »

  1.   

    就是  我鼠标不是把  “光临”两个字给选中了吗,现在我function里面需要把这个内容“光临”给取出来,怎么做啊?
      

  2.   

    给你一个思路,textarea的onblur 写个事件,当你移除这个文本域的时候,判断当前选区,如果为空的话,则不复制,否则复制,或者剪贴嘛
      

  3.   


    能QQ交流吗。[email protected]
    我也觉得我似乎事件弄错了,但是我的想法就是在一篇很长的文章里面,如果你看中了那句话,你就把选中,自动处理
    或者做成像   360浏览器那样,他有个选中文本,然后弹出一个小提示,复制或者立即搜索 这种特效也是非常的好的,
    就不是不知道该怎么做啊?
      

  4.   


        <textarea id="TextArea1" rows="2" cols="20">我们和你们这是什么</textarea>
        <br /><br />
        <input id="Text1" type="text" />首先获得TextArea,然后取得其value,再用slice得到从选择区开始到结束的文本。
    在你选中文本的时候,input Text1的内容会变成你选择的文本。    <script>
            var txt = document.getElementById("TextArea1");
            txt.onselect = function () {
                document.getElementById("Text1").value = txt.value.slice(txt.selectionStart, txt.selectionEnd);
            };
        </script>
    测试正常。结贴给分!
      

  5.   


    能不能写个完整的给我,我位置是不是放错了,选中了还是没有反应啊[/quote
      

  6.   


    能不能写个完整的给我,我位置是不是放错了,选中了还是没有反应啊[/quote好的!!!谢谢你啊!非常感谢,40分全给你!!
    如果你感兴趣,也可以帮我把360浏览器那个帮我弄出来呗,
    最好是写成JS文件最好了,
      

  7.   

    写了个方法,我这边测试过了  没问题,不过火狐不兼容,其他浏览器都没问题,火狐的我再看看:<textarea cols="20" rows="5" onselect="selected()">Hello world!</textarea>
    function selected(){
    if (document.selection && document.selection.createRange) {
    alert(document.selection.createRange().text);
    }else if (window.getSelection) {
    alert(window.getSelection().toString());
    }
    }
      

  8.   

    或者你可以上我的博客看看效果,我刚刚把这个效果写到博客上去了:http://www.ljiong.com/?p=127
      

  9.   


    请高手给个源代码我可以吗,最好是有360浏览器的那种做法最好了不好意思我看错了你的问题<html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <head>
        <script type="text/javascript">
            var agt=navigator.userAgent.toLowerCase();
            var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));        function selecttext(dom){
                //var myArea = document.getElementById("s");
                var myArea = dom;
                var selection;
                if (!ie){
                    if (myArea.selectionStart!= undefined) {
                        selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);
                    }
                }else{
                    if (window.getSelection){
                        selection = window.getSelection();
                    }else if (document.getSelection){
                        selection = document.getSelection();
                    }else if (document.selection){
                        selection = document.selection.createRange().text;
                    }
                }
                return selection;
            }        function copytext(event)
            {
                // 这里怎么做,取出选择的文本内容呢
                //alert(event.selection.createRange.duplicate.text)
                var selection = selecttext(event.srcElement || event.target);            alert(selection);
            }    </script>
    </head>
    <body >
    <form name="form1" method="post" action="">
        <textarea name="textfield" cols="40" rows="10" wrap="VIRTUAL" onselect="copytext(event)">欢迎光临!</textarea>
    </form>
    </body>
    </html> 
      

  10.   


    请高手给个源代码我可以吗,最好是有360浏览器的那种做法最好了不好意思我看错了你的问题<html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <head>
        <script type="text/javascript">
            var agt=navigator.userAgent.toLowerCase();
            var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));        function selecttext(dom){
                //var myArea = document.getElementById("s");
                var myArea = dom;
                var selection;
                if (!ie){
                    if (myArea.selectionStart!= undefined) {
                        selection = myArea.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart);
                    }
                }else{
                    if (window.getSelection){
                        selection = window.getSelection();
                    }else if (document.getSelection){
                        selection = document.getSelection();
                    }else if (document.selection){
                        selection = document.selection.createRange().text;
                    }
                }
                return selection;
            }        function copytext(event)
            {
                // 这里怎么做,取出选择的文本内容呢
                //alert(event.selection.createRange.duplicate.text)
                var selection = selecttext(event.srcElement || event.target);            alert(selection);
            }    </script>
    </head>
    <body >
    <form name="form1" method="post" action="">
        <textarea name="textfield" cols="40" rows="10" wrap="VIRTUAL" onselect="copytext(event)">欢迎光临!</textarea>
    </form>
    </body>
    </html> 
    好 谢谢 非常感谢!!!
      

  11.   


    好 非常感谢 再请你帮忙解决这个问题:
    http://ask.csdn.net/questions/152128
      

  12.   


    好 非常感谢 再请你帮忙解决这个问题:
    http://ask.csdn.net/questions/152128这个问题  我不懂哟,  不过你如果只是要复制功能的话,可以百度搜索【js复制到剪贴板】,就有解决方法
      

  13.   


    http://ask.csdn.net/questions/152128
    请高手看下这个问题
      

  14.   

    昨天写了一下类似360选择后提示的那个功能,你可以参考下:
    http://www.ljiong.com/?p=137
      

  15.   


    你太棒了,我现在又出现了新的问题,还是上面那个选择内容,我现在不给他弹出来,而是想要再写进另外一个文本框textarea中,如何实现它的每次换行呢?
       
     function copytext(event)
        {
            // 这里怎么做,取出选择的文本内容呢
            //alert(event.selection.createRange.duplicate.text)
            var selection = selecttext(event.srcElement || event.target);        var old_value = document.getElementById("textid").value;
            var new_value = old_value+selection;
           // document.getElementById("textid").value = new_value;
            document.getElementById("textid").value.innterHtml("<<!DOCTYPE html>
            <html>
            <head>
             <title></title>
            </head>
            <body>"+
            new_value+"</br>
            </body>
            </html>")
        }上面的textid是下面的这个东西:
    <textarea id="textid" wrap="hard" style="width:400px;height:550px;"></textarea>
      

  16.   


    关于换行已经实现了,我想复杂了,    function copytext(event)
        {
            var selection = selecttext(event.srcElement || event.target);        //alert(selection);
            var old_value = document.getElementById("textid").value;
            if(old_value==null||old_value=="")
             new_value = selection;
            else
             new_value = old_value+"\n"+selection;
            document.getElementById("textid").value = new_value;
        }
      

  17.   


    刚刚发现有个小问题:
    用IE浏览器的时候,这个选中问题,然后再让他自动写到其他的文本框里,太灵敏了,应该改成onmouseup事件,这个是个小缺点,你看下。看看像不像金字塔