开发者

How can I improve this click/toggle function in jquery?

$('.tabs a ').click(function () {
    var a = $(this).attr('href');
    if (a == '#tab-1') {
        $('.btn-buy').hide();
        $('.btn-sell').show();
    } else {
        $('.btn-sell').hide();
        $('.btn-buy').show();
    }
    return false;
});

... it works, but the code is ug开发者_如何学编程ly, too many lines. Can it be reduced any further?

Thanks in advance for your help!


You could just use toggle:

$(".tabs a").click(function() {
    $(".btn-buy").toggle();
    $(".btn-sell").toggle();
});

This would assume they start out in their correct state initially...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜