[英]How to Use jQuery select() to select content of a div in a popup?
Hi all i am working on jquery i need to Use jQuery select() to select content of a div in a popup i had written code in the html page it's working fine but when comes to poup it dosen't work大家好,我正在研究 jquery 我需要使用 jQuery select() 在弹出窗口中选择 div 的内容
here i am calling a pop up in that pop up i have a div in that div i have a button in that i am calling a callingmethod();在这里,我在那个弹出窗口中调用一个弹出窗口 我在那个 div 中有一个 div 我有一个按钮,我正在调用一个调用方法(); but i's not working
但我没有工作
do i have to change anything in this code please help to make it thanks in advance here my code我是否必须更改此代码中的任何内容,请帮助使其提前在此感谢我的代码
<input type="button" id="btncall" onclick="callingmethod('selectable');" value="c0py" />
text to be copy要复制的文本
<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>
here is a calling function这是一个调用函数
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);
}
}
You don't have an element having an id of selectable
anywhere in your code.您的代码中的任何地方都没有具有
selectable
id 的元素。 And thus, are getting an error.因此,出现错误。
Add the following to your html file:将以下内容添加到您的 html 文件中:
<input type='text' id='selectable' />
Type something into it.在里面输入一些东西。 And press copy.
并按复印。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.