开发者

Handle blurring of each field in a form with jQUery

I've got a form and I need to post data to the server every time a field in the form is changed. How do I apply a function to each child element of the form on blur开发者_如何学Python?


Try something like this:

$('form#yourform > input').blur(function(){
    // Do Server Request here.
}); 


I've created update() as the function that posts to the server and used the following:

        $( 'input' ).blur( function() {
            update();
        }); 

        $( 'input[type=checkbox]' ).click( function() {
            update();
        });

        $( 'textarea' ).blur( function() {
            update();
        });

        $( 'select' ).change( function() {
            update();
        });


This will work:

$('input, select').blur(function(){ // function definition });

Also:

$('form input, form select').blur(function(){ // function definition });

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜