我有一些代碼,允許用戶輸入數據到引導日期選擇器,然後單擊提交按鈕和日期顯示在navpanel內。在按鈕上單擊我有一個JavaScript函數,將確定用戶在哪個選項卡上,並將在MVC控制器中運行C#函數。我目前有兩個函數DelayedSpiffDate,InstantSpiffDate。出於某種原因,即使選中了instantspiff選項卡,它也只會加載DelayedSpiffDate函數。我不確定我做錯了什麼?這裏是我的html:Bootstrap navpanel和日期選擇器JavaScript調用C#控制器
<div class="row-fluid 1">
<div class="col-lg-12 delayed_spiff_body">
<div class="row spiff-datepicksection">
<div class="col-lg-6 pull-right">
<div class="col-sm-5 col-lg-offset-4">
<div class="form-group">
<div class="input-group date">
<input type="text" id="startDate" class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-lg-3">
<input class="spiffdate-btn" type="button" value="Submit" />
</div>
</div>
</div>
<div class="row spiff_tabs_body">
<!-- Nav tabs -->
<ul class="nav nav-tabs spiff_tabs" role="tablist">
<li role="presentation" class="active">
<a href="#home" aria-controls="home" role="tab" data-id="delayedspiff" data-toggle="tab" onclick="FormGet('dashboard/delayedspiff', 'delayedspiff')">Potential Spiff</a>
</li>
<li role="presentation">
<a href="#profile" aria-controls="profile" role="tab" data-id="instantspiff" data-toggle="tab" onclick="FormGet('dashboard/instantspiff', 'delayedspiff')">Instant Spiff</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="delayedspiff"></div>
<div role="tabpanel" class="tab-pane" id="instantspiff"></div>
</div>
</div>
</div>
</div>
下面是我的javascript:
$(".spiffdate-btn").click(function(){
var correctid = $(".tab-content .active").attr("id");
var startDate = $("#startDate").val();
if (correctid == "delayedspiff")
$.get("@Url.Action("DelayedSpiffDate", "Dashboard")", { startDate: startDate });
else
$.get("@Url.Action("InstantSpiffDate", "Dashboard")", { startDate: startDate });
});
更新的javascript:
$(".spiffdate-btn").click(function(){
var correctId = $("ul.spiff_tabs li.active a").attr('data-id');
console.log(correctId);
var startDate = $("#startDate").val();
if (correctId == "delayedspiff")
{
$.get("@Url.Action("DelayedSpiffDate", "Dashboard")", { startDate: startDate });
} else if (correctId == "instantspiff") {
$.get("@Url.Action("InstantSpiffDate", "Dashboard")", { startDate: startDate });
}
});
檢查你是否在'correctid'中添加了正確的id,比如'condition.log(correctid)'前面的條件。 –
@ ZakariaAcharki我沒有得到糾正的正確ID。即使選中了instantspiff選項卡,它也會顯示delayedspiff。 – hollyquinn
我收到了正確的ID。問題是$ .get應該失敗,因爲第一個參數是多個字符串而不是一個封裝。 – Brant