我想知道是否有人能够提供一个示例,说明如何通过jquery在页面加载时从asp.net单选按钮列表控件中获取所选单选按钮选项。
谢谢。
谢谢。
var selected = jQuery('#<%= MyRadioButtonList.ClientID %> input:checked').val();
// or ...
var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val();
$(document).ready(function(){
var selected = $('#<%= MyRadioButtonList.ClientID %> input:checked').val();
$("#<%= MySampleLabel.ClientID %>").text(selected);
}
这里有一个工作示例here。
我使用的选择器将获取页面上所有带有类ofinterest
的单选按钮。
$(function(){
var value = $('input.ofinterest:checked').val();
$('#result').text(value);
});
protected void radioButton_CheckedChanged(object sender, EventArgs e)
{
throw new ApplicationException("Radio Changed");
RadioButton rb = (RadioButton)sender;
TextBox tbexact = (TextBox)this.UpdatePanel1.FindControl("TextBoxExact");
TextBox tbpartial = (TextBox)this.UpdatePanel1.FindControl("TextBoxPartial");
DropDownList dropdown = (DropDownList)this.UpdatePanel1.FindControl("DropDownListCountries");
RadioButton rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonExact");
if (tbexact == null)
throw new ApplicationException("Could not find control");
else
throw new ApplicationException("Found it");
if (rbc != null && rb.Equals(rbc))
{
tbpartial.Enabled = false;
dropdown.Enabled = false;
mCriteria = SearchCriteria.Exact;
}
rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonPartial");
if (rbc != null && rb.Equals(rbc))
{
tbexact.Enabled = false;
dropdown.Enabled = false;
mCriteria = SearchCriteria.Partial;
}
rbc = (RadioButton)this.UpdatePanel1.FindControl("RadioButtonPerCountry");
if (rbc != null && rb.Equals(rbc))
{
tbexact.Enabled = false;
tbpartial.Enabled = false;
mCriteria = SearchCriteria.Country;
}
}