开发者

one button multiple click handler in jquery

开发者 https://www.devze.com 2023-03-24 00:52 出处:网络
I\'m new to jQuery. I have this button #sess_s which should execute three click handlers. It works fine usually, but sometimes it will miss one or two click handlers. I want all three to work together

I'm new to jQuery. I have this button #sess_s which should execute three click handlers. It works fine usually, but sometimes it will miss one or two click handlers. I want all three to work together when clicked. Any easy way? Thanks.

My code:

$('#sess_s').click(function() {
    $.post('sdata.php',{id_value: id_form.id_data.value  },
           function(output) {
               $('#sess_feed').html(output).show();
           });
});

$('#sess_s').click(function() {
    $.post('ssdata.php',
           function(output) {
               $('#sess_feed1').html(output).show();
           });
});

$('#sess_s').click(function() {
    $.post('ses_count.php',
           开发者_运维问答function(output) {
               $('#ses_count').html(output).show();
           });
});


 $('#sess_s').click(function() {
        $.post('sdata.php',{id_value: id_form.id_data.value  },
           function(output) {
           $('#sess_feed').html(output).show();
        });

        $.post('ssdata.php',
           function(output) {
           $('#sess_feed1').html(output).show();
        });


        $.post('ses_count.php',
           function(output) {
           $('#ses_count').html(output).show();
        });


 });


you can combine them:

$('#sess_s').click(function() {
    $.post('ssdata.php', function(output) {
        $('#sess_feed1').html(output).show();
    });
    $.post('ses_count.php', function(output) {
        $('#ses_count').html(output).show();
    });
    $.post('sdata.php', {
        id_value: id_form.id_data.value
    }, function(output) {
        $('#sess_feed').html(output).show();
    });
});


Try to attach one event handler but put all three code blocks inside one function:

Something like this:

$('#sess_s').click(function() {
    $.post('sdata.php'...
    $.post('ssdata.php'...
    $.post('ses_count.php'...
});

This is simplified, of course. You might want to wrap up every block with try/catch in case one fails...

0

精彩评论

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