选择并复制文本到剪贴板双击jQuery
这个问题在这里已经有了答案:
function selectElementContents(el) {
if (window.getSelection && document.createRange) {
var sel = window.getSelection();
var range = document.createRange();
range.selectNodeContents(el);
sel.removeAllRanges();
sel.addRange(range);
} else if (document.selection && document.body.createTextRange) {
var textRange = document.body.createTextRange();
textRange.moveToElementText(el);
textRange.select();
}
}
<h1 onclick="selectElementContents(this)">Owl PvP</h1>
<h2 onclick="selectElementContents(this)">play.owlpvp.net</h2>
链接地址: http://www.djcxy.com/p/19739.html
上一篇: Select and copy text to clipboard on double click jQuery