用javascript获取选中的文字

function getSelectText() {

              return document.selection && document.selection.createRange().text || window.getSelection && window.getSelection() || document.getSelection && document.getSelection() || '';

}

 

function getSelectText()
{
    var txt = null;
    if (window.getSelection){  // mozilla FF 
        txt = window.getSelection();
    }else if (document.getSelection){
        txt = document.getSelection();
    }else if (document.selection){  //IE
        txt = document.selection.createRange().text;
    }
    return txt;
}

 

posted @ 2012-01-04 20:44  风去无痕  阅读(193)  评论(0编辑  收藏  举报