[英]jQuery - on text change while user typing or paste
I'm new to jQuery and I've tried to make something but I failed so here is my problem when the user type it works but when the user paste something didn't work !! 我是jQuery的新手,但我尝试制作某些东西,但是失败了,所以这是我的问题,当用户键入它起作用但当用户粘贴某些东西不起作用时!
$(document).ready(function(){
$('#username').keyup(username_check);
});
the username_check function : username_check函数:
function username_check(){
var username = $('#username').val();
if(username == "" || username.length < 4){
alert("error");
}
the field : 场 :
<input type="text" id="username" name="username" required>
Use .on()
or .bind()
to bind multiple events, 使用
.on()
或.bind()
绑定多个事件,
$(document).ready(function(){
$('#username').on('keyup paste',username_check);
});
function username_check(){
setTimeout( function() {
var username = $('#username').val();
},100);
if(username == "" || username.length < 4){
alert("error");
}
}
如果要捕获所有input
事件:
$('#username').on("input", username_check);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.