标签:blog io ar java for sp div on log
【ASPXソース】
<%-- クリックするとアラート表示--%>
<input id="button1" type="button" value="選択表示"
onclick="getCheckedRadio(‘<%= RadioButtonList1.ClientID %>‘)"/>
<%-- ラジオボタンリスト--%>
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>AAA</asp:ListItem>
<asp:ListItem Selected="True">BBB</asp:ListItem>
<asp:ListItem>CCC</asp:ListItem>
</asp:RadioButtonList>
【javascript(jQuery)ソース】
//この引数idはコントロールIDの文字列を渡してください。
function getCheckedRadio(id) {
//各Itemの配列を取得
//↓javascriptならこれ
var radio = document.getElementById(id).getElementsByTagName("input");
//↓jQueryならこれ
//var radio = $("#" + id + " :radio");
for (var j = 0; j < radio.length; j++) {
//選択されたラジオボタンの時
if (radio[j].checked)
//アラート表示
alert(radio[j].value);
}
}
これで、選択表示ボタンをクリックすると、「BBB」のアラートが表示されます。
これを応用して、いろいろできそう。
javascript RadioButtonList 選択値
标签:blog io ar java for sp div on log
原文地址:http://www.cnblogs.com/haiy/p/4079147.html