JQuery 变量获取对象 ID,其值等于另一个未评估的变量中设置的值

JQuery Variable Gets Object ID With Equals Value Set in Another Variable Which is not Evaluating

<script type="text/javascript">

            $(".RecentFeedToogle .Tab").click(function(e){

                width = $(this).attr('id');
                RecentBananzaNews = '164px';
                RecentRaffles = '112px';
                RecentArticles = '114px';
                RecentForumDiscussions = '109px';
                RecentCharitableNews = '182px';
                if ($(this).width() === 44) {

                    $(".RecentFeedToogle .Tab.Active").animate({width:'44px'},500);
                    $(".RecentFeedToogle .Tab").removeClass('Active');
                    $(this).animate({width: width },500);
                    $(this).addClass('Active');
                };
            });
</script>

$(this).animate({width: width },500); 在我的脚本中,width : width,“width”变量返回被单击对象的 ID 而不是附加变量值。

HTML 是这样的:

<!-- Recent Feed Starts -->
            <div class="RecentFeed">

                <!-- Switch Feed Starts -->
                <div class="RecentFeedToogle">
                    <div class="Tab Active" id="RecentBananzaNews">
                        <div class="Icon"></div>
                        <div class="Title">Bananza News</div>
                        <div class="Arrow"></div>
                    </div>

试试下面的代码,

<script type="text/javascript">
$(".RecentFeedToogle .Tab").click(function(e){
    var divwidth = '';
    if($(this).attr('id') == 'RecentBananzaNews'){
        divwidth = '164px';
    }
    if($(this).attr('id') == 'RecentRaffles'){
        divwidth = '112px';
    }
    if($(this).attr('id') == 'RecentArticles'){
        divwidth = '114px';
    }
    if($(this).attr('id') == 'RecentForumDiscussions'){
        divwidth = '109px';
    }
    if($(this).attr('id') == 'RecentCharitableNews'){
        divwidth = '182px';
    }
    if ($(this).width() === 44) {
        $(".RecentFeedToogle .Tab.Active").animate({width:'44px'},500);
        $(".RecentFeedToogle .Tab").removeClass('Active');
        $(this).animate({width: divwidth },500);
        $(this).addClass('Active');
    }
});
</script>