Home > Web Front-end > JS Tutorial > Code for selecting textarea text under javascript compatible with firefox_form effects

Code for selecting textarea text under javascript compatible with firefox_form effects

WBOY
Release: 2016-05-16 19:03:43
Original
955 people have browsed it

主要用到的js代码

复制代码 代码如下:

function getSelectedText(){
        var selectedText;
        var textField=document.getElementById('inputTextarea');
        if(window.getSelection) selectedText=getTextFieldSelection(textField);//getTextFieldSelection(document.getElementById("inputTextArea"));
        else selectedText=document.selection.createRange().text;
            alert(selectedText);
    }

    function getTextFieldSelection(e){
        //var oEvent=arguments.callee.caller.arguments[0];
        if(e.selectionStart != undefined && e.selectionEnd != undefined)
            return e.value.substring(e.selectionStart,e.selectionEnd);
        else return "";
    }

千万别相信我说的事情,我从来就没有这么勇敢过,这么壮烈过。我不断发誓要老老实实讲故事,可是说实话的愿望有多强烈,受到的各种干扰就有多大。我悲哀地发现根本就无法还原真相。记忆总是被我的情感改头换面,并随之捉弄我,背叛我。把我搞得头昏脑胀,真假难辩。
  • 获取选中的文字段

  • [Ctrl A 全选 注:如需引入外部Js需刷新才能执行
    ]
    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template