天天看點

為bootstrap的tab增加請求操作

前言:在進行 bootstrap 的tab切換操作時,我們有的時候需要為其增加請求操作,用來擷取服務端的資料。

$('#myTab a').click(function(e) {
        // 先擷取項目id
        var deal_id = $("#deal_id").val();
        var tabIndex = $("#tabIndex").val();

        var href = $(this).attr("href");

        if (href == '#program') {// 項目基本資訊
            if (tabIndex == 1) {
                if (deal_id) {
                    location.href = common.ctx + "/project/showProjectBasicInfo?deal_id=" + deal_id;
                } else {
                    location.href = common.ctx + "/project/initProjectBasicInfo";
                }
            } else {
                $(this).tab('show');
            }

        } else if (href == '#reback') {// 項目回報資訊
            if (deal_id && !tabIndex) {
                location.href = common.ctx + "/project/showProjectRebackInfo?deal_id=" + deal_id + "&tabIndex=1";
            } else {
                $(this).tab('show');
            }
        }

        e.preventDefault();// 取消事件的預設動作
    });      

我們利用a标簽的點選事件,然後對tab記性判斷後,改變位址欄請求。