有没有办法检测右键单击,然后在 IE 和 Firefox 上使用 JavaScript 粘贴?
更新:
我决定使用 Jquery 来做到这一点:
$('#controlId').bind('paste', null, function() {
// code
});
这不是我想要的(因为它在“ctrl + v”以及“右键单击+粘贴”中被触发,但我可以解决它。
在 Chrome、Firefox 3、IE 7 和 IE 6 上测试它并且它正在工作
有没有办法检测右键单击,然后在 IE 和 Firefox 上使用 JavaScript 粘贴?
更新:
我决定使用 Jquery 来做到这一点:
$('#controlId').bind('paste', null, function() {
// code
});
这不是我想要的(因为它在“ctrl + v”以及“右键单击+粘贴”中被触发,但我可以解决它。
在 Chrome、Firefox 3、IE 7 和 IE 6 上测试它并且它正在工作
我喜欢这个解决方案:
$('#txt_field').bind('input propertychange', function() {
console.log($(this).val());
});
$('#controlId').bind('paste', null, function(e) {
if(!e.keyCode){
/*
since no key was down at the time of the event we can assume it was
from the toolbar or right click menu, and not a ctrl+v
*/
}
});
使用 IE,您可以使用 onpaste
使用 Mozilla,您可以查看 oninput 和
elementReference.addEventListener("DOMCharacterDataModified", function(e){ foo(e);}, false);
没有简单的馅饼解决方案。
埃里克
使用setTimeout()
,设置小的超时直到 .val() func 可以被填充。
$(document).on('paste blur keyup', '#controlId', function(event) {
var element = $(event.target);
setTimeout(function() {
var text = $(element).val();
// do something with text
}, 100);
});
来源:捕捉粘贴输入
我在 IE8 中遇到了同样的问题。Chrome 允许我识别右键单击粘贴,但 IE8 不能。
我能够使用 Aaron 描述的鼠标离开功能解决 JQUERY 的问题,但这里是代码:
for IE8:
$( "#field" ).mouseleave(function() {
doStuff());
});
for Chrome:
$('#field').bind('input',function() {
doStuff();
});