我对jquery有疑问。
我知道我们可以用这样的jquery检测副本:
$("#textA").bind('copy', function() {
$('span').text('copy behaviour detected!')
});
$("#textA").bind('paste', function() {
$('span').text('paste behaviour detected!')
});
$("#textA").bind('cut', function() {
$('span').text('cut behaviour detected!')
});
但是,我想知道什么是完全复制的?
例如,用户复制一个框的值,我需要得到并拥有该值。
如何使用jquery执行此操作?
答案 0 :(得分:2)
您可以使用此
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
$(document).keypress("c",function(e) {
if(e.ctrlKey)
alert(getSelectionText());
});
这应该是工作