复制代码 代码如下:
functiongetSelectedText(){
varselectedText;
vartextField=document.getElementById('inputTextarea');
if(window.getSelection)selectedText=getTextFieldSelection(textField);//getTextFieldSelection(document.getElementById("inputTextArea"));
elseselectedText=document.selection.createRange().text;
alert(selectedText);
}
functiongetTextFieldSelection(e){
//varoEvent=arguments.callee.caller.arguments[0];
if(e.selectionStart!=undefined&&e.selectionEnd!=undefined)
returne.value.substring(e.selectionStart,e.selectionEnd);
elsereturn"";
}
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]