[英]How to Use jQuery select() to select content of a div in a popup?
大家好,我正在研究 jquery 我需要使用 jQuery select() 在彈出窗口中選擇 div 的內容
在這里,我在那個彈出窗口中調用一個彈出窗口 我在那個 div 中有一個 div 我有一個按鈕,我正在調用一個調用方法(); 但我沒有工作
我是否必須更改此代碼中的任何內容,請幫助使其提前在此感謝我的代碼
<input type="button" id="btncall" onclick="callingmethod('selectable');" value="c0py" />
要復制的文本
<div id="selectable">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Quisque eu ante ac massa dignissim tempor id nec lectus. Vestibulum commodo purus
vel nisl vulputate ac porttitor erat luctus. </div>
這是一個調用函數
function callingmethod(containerid) {
if (document.selection) {
alert(1);
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select();
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
}
}
您的代碼中的任何地方都沒有具有selectable
id 的元素。 因此,出現錯誤。
將以下內容添加到您的 html 文件中:
<input type='text' id='selectable' />
在里面輸入一些東西。 並按復印。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.