[英]jQuery alternative to keyup
I'm trying to write something which will detect input in a form field, but I want it to be triggered not just on a keypress but if the user were also to hold a key down for multiple repeat characters, or if they were also to copy & paste something into the input field. 我正在尝试编写一些可以在表单字段中检测输入的内容,但是我希望它不仅可以在按键上触发,而且如果用户还要为多个重复字符按住键,或者如果它们也是将某些内容复制并粘贴到输入字段中。
I've tried using keyup
event but this does not meet all my requirements, and change
event doesn't seem to be a good fit either. 我尝试过使用
keyup
事件,但这并不符合我的所有要求,而且change
事件似乎也不合适。 Please can anyone advise an event which may be more suitable? 请问任何人都可以建议一个更合适的活动吗?
Thank you. 谢谢。
You might be looking for jQuery's input
event. 您可能正在寻找jQuery的
input
事件。
$('inputSelector').on('input', function() {});
Look at the following JSFiddle for an example: http://jsfiddle.net/philfreo/MqM76/ 请看以下JSFiddle的示例: http : //jsfiddle.net/philfreo/MqM76/
您可以直接使用输入的HTML标记和函数名称,如下例所示: http : //www.w3schools.com/jsref/tryit.asp? oninput
Do you want to run the same function for either keydown
, keyup
or paste
? 你想为
keydown
, keyup
或paste
运行相同的功能吗?
$(document).ready(function(){
$( "#testingInput" ).on( "keydown keyup paste", function() {
console.log("running for keydown keyup paste!");
});
});
If not you can just run each one depending on the event: 如果没有,你可以根据事件运行每一个:
$( "#testingInput" ).on( "keydown", function() {});
$( "#testingInput" ).on( "keyup", function() {});
$( "#testingInput" ).on( "paste", function() {});
https://jsfiddle.net/bhqme6ze/1/ https://jsfiddle.net/bhqme6ze/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.