Select and copy text to clipboard on double click jQuery
This question already has an answer here:
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/19740.html
上一篇: 使用基数较低的索引是否合理?
下一篇: 选择并复制文本到剪贴板双击jQuery