jQuery交换id

时间:2013-03-23 14:07:52

标签: jquery attr

我交换了div。当我点击#inactive ID时,#active-page应该会消失,#inactive-page应该会出现。此外,#active id应该成为#inactive id,反之亦然。我使用了质量为#inactive-page-swap#inactive-page的质量为#active-swap#active的质量为#inactive的id {= 1}}。

问题是 - 当我点击#active-page ID时,#inactive-page消失但<script> $(document).ready(function(){ $("#inactive").click(function(){ $(#inactive).attr("id","active-swap"); $("#active").attr("id","inactive"); $("#active-swap").attr("id","active"); $("#active-page").attr("id","inactive-page-swap",function(){ $("#inactive-page").attr("id","active-page"); $("#inactive-page-swap").attr("id","inactive-page"); }); }); }); </script> 没有出现。

{{1}}

请帮帮我!!!

1 个答案:

答案 0 :(得分:0)

试试这个......

$(document).ready(function(){
    $("#inactive").click(function(){
        var id = $(this).attr('id');
        inactive = $('#inactive');
        active = $('#active');
        swap = $('#active-swap');
        inactive.attr('id', 'active-swap');
        active.attr('id', 'inactive');
        swap.attr('id', 'active');
        inactive = $('#active-page');
        inactivepage = $('#inactive-page');
        inactiveswap = $('#inactive-page-swap');
        $(inactive).attr("id","inactive-page-swap");
        $(inactivepage).attr("id","active-page");
        $(inactiveswap).attr("id","inactive-page");
    });
});

请参阅此jsFiddle example