开发者

JQuery Change Event Problem

I have a problem with Change event . I want to do a request using ajax every time that the input value changes = keyup , past , cut.... the change event 开发者_开发百科in jQuery is too slow !!

$("#Password").change(function (){
    $.post("register.php", {do : 'password', pass : $(this).val()}, function (data){
        alert(data);
    });
});

Thx Every One I Opened A Plugin Called Elastic and I find what I am looking for :

$(Your Selectors).bind('keyup change cut paste', function(){
    //do things
});

It's Perfect ^^ !!


You can do a few things to cover all bases if you want:

$("#Password").bind('action_taken',function (){
    $.post("register.php", {do : 'password', pass : $(this).val()}, function (data){
        alert(data);
    });
}).blur(function(){
       $(this).trigger('action_taken'); //call action_taken on blur
}).change(function(){
       $(this).trigger('action_taken'); //call action_taken on change
}).keyup(function(){
       $(this).trigger('action_taken'); //call action_taken on keyup
});


I guess you can have an alternative of storing input value in a variable, and checking for keyup (and comparing the current value to the previous value) only when that field has focus to trigger your ajax request.

you can get the element in focus using document.activeElement or for jquery 1.6+, the :focus selector

for the problem of pasting with mouse, you can repeat the eventlistener for left mouse click

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜