日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

获取网页中选中的文字

發布時間:2023/12/13 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 获取网页中选中的文字 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

獲取頁面中選中的文字

//獲取頁面中選中的文字 function getSelectedText(){if(window.getSelection){ //FFreturn window.getSelection().toString();}else{ //IEreturn document.selection.createRange().text;} }


設置或獲取輸入框的選中文字

//設置文字選中 function setSelectText(editor, text) {if (!editor) return;editor.focus();if (editor.document && editor.document.selection)editor.document.selection.createRange().text = text;else if ("selectionStart" in editor) {var str = editor.value, start = editor.selectionStart;editor.value = str.substr(0, start) + text + str.substring(editor.selectionEnd, str.length);editor.selectionStart = start + text.length;editor.selectionEnd = start + text.length;} } //獲取選中的文字 function getSelectText(editor) {if (!editor) return; editor.focus();if (editor.document && editor.document.selection)return editor.document.selection.createRange().text; else if ("selectionStart" in editor)return editor.value.substring(editor.selectionStart, editor.selectionEnd); }



轉載于:https://www.cnblogs.com/flyjs/archive/2012/02/26/2368583.html

總結

以上是生活随笔為你收集整理的获取网页中选中的文字的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。