2012-06-08 51 views
1

我有一個奇怪的問題。我有一個單選按鈕列表,當它被選中時,它會顯示下面對應選定項目的div。單選按鈕列表上方是複選框列表。單選按鈕單擊事件正常工作,直到您從上面的複選框列表中選中一個框。一旦從上面的複選框列表中檢查了一個項目,它就會開始返回「on」而不是所選單選按鈕的值。任何想法?jQuery RadioButtonList檢查值返回「on」

的jQuery:

<script type="text/javascript"> 
function CheckAllTrucks(sendingcb) { 
    $("#divTruckList :checkbox").prop("checked", $(sendingcb).prop("checked")); 
} 

function SetTimeframeInput(sendingrbl) { 
    var value = $(sendingrbl + ":checked").val(); 

    $("#divTimeFrameControls .timeframectrls").each(function() { 
     $(this).hide(); 
    }); 

    $("#div" + value).show(); 
} 

HTML/ASP.NET代碼:

<div class="form-field"> 
    <asp:CheckBox ID="cbSelectAllTrucks" runat="server" Text="Select All Trucks" onclick="CheckAllTrucks(this)" /> 
    <div id="divTruckList"> 
     <asp:CheckBoxList ID="cblTrucks" runat="server" /> 
    </div> 
</div> 
<div class="form-field"> 
    <asp:RadioButtonList ID="rblTimeFrame" runat="server" onclick="SetTimeframeInput(this)"> 
     <asp:ListItem Text="Month" Value="month" /> 
     <asp:ListItem Text="Quarter" Value="quarter" /> 
     <asp:ListItem Text="January-December" Value="jandec" /> 
     <asp:ListItem Text="July-June" Value="juljun" /> 
    </asp:RadioButtonList> 
    <div id="divTimeFrameControls"> 
     <div id="divmonth" class="timeframectrls" style="display: none;"> 
      <!-- month fields --> 
     </div> 
     <div id="divquarter" class="timeframectrls" style="display: none;"> 
      <!-- quarter fields --> 
     </div> 
     <div id="divjandec" class="timeframectrls" style="display: none;"> 
      <!-- jandec fields --> 
     </div> 
     <div id="divjuljun" class="timeframectrls" style="display: none;"> 
      <!-- juljun fields --> 
     </div> 
    </div> 
</div> 

提前感謝!

編輯

我發現這個只有當一個複選框檢查情況。如果您檢查並取消選中,則該值仍然正確。只有當複選框被選中時,它纔會將值設置爲「on」。

回答

0

仍然不知道問題是什麼,但能夠通過直接引用單選按鈕列表的ID來修復它。像這樣:

function SetTimeframeInput() { 
    var value = $("#rblTimeFrame input:checked").val(); 

    $("#divTimeFrameControls .timeframectrls").each(function() { 
     $(this).hide(); 
    }); 

    $("#div" + value).show(); 
} 

感謝您的輸入。

+0

你知道,你可以將你的問題標記爲答案:) – Jashwant

+0

它不會讓我將自己的答案標記爲2天的答案。 – Ricketts

0

不是傳遞(this)到功能嘗試使用EventObject這是默認傳遞點擊:

function SetTimeframeInput(e) { 
    var value = $(e.currentTarget).val(); 

// value contains selected radio button`s value 

// continue your code here 

}

我希望這有助於。

+0

當我提出你所提到的改變時,e是未定義的。 – Ricketts