![](/img/trans.png)
[英]Using execCommand (Javascript) to copy hidden text to clipboard
[英]execCommand not working in javascript jQuery to copy text to clipboard
我正在嘗試將文本復制到剪貼板。 但是已經在模式窗口中顯示了在ajax調用之后出現的文本。代碼如下:
jQuery.fn.selectText = function(){
var doc = document
, element = this[0]
, range, selection
;
if (doc.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
所以在range = document.createRange();
我嘗試插入range.execCommand('copy');
因為我已經閱讀了本教程,但它沒有提到這個命令的任何問題。 我得到的錯誤如下:
TypeError: range.execCommand is not a function
范圍沒有execCommand
函數, execCommand
函數屬於document
對象。
取自相同的教程:
當HTML文檔切換到designMode時,文檔對象公開execCommand方法,該方法允許運行命令來操作可編輯區域的內容。 大多數命令會影響文檔的選擇(粗體,斜體等),而其他命令會插入新元素(添加鏈接)或影響整行(縮進)。 使用contentEditable時,調用execCommand將影響當前活動的可編輯元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.