开发者

Handle blurring of each field in a form with jQUery

开发者 https://www.devze.com 2022-12-23 19:37 出处:网络
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 l

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

精彩评论

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

关注公众号