[英]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.