Javascript 如何防止鼠标中键粘贴到输入中?
鼠标中键将值粘贴到输入字段中。我想覆盖这个功能。有可能吗? 我使用以下代码,但它不阻止默认粘贴:Javascript 如何防止鼠标中键粘贴到输入中?,javascript,Javascript,鼠标中键将值粘贴到输入字段中。我想覆盖这个功能。有可能吗? 我使用以下代码,但它不阻止默认粘贴: $('input').on('mouseup',function(e){ //middle button is clicked if (e.which == 2) { e.preventDefault(); $(this).val('another value'); } }) 您只需取消mousedown事件,而不是mouseup
$('input').on('mouseup',function(e){
//middle button is clicked
if (e.which == 2)
{
e.preventDefault();
$(this).val('another value');
}
})
您只需取消
mousedown
事件,而不是mouseup
这里有一个现场演示: