У меня есть пользовательский веб-элемент управления, который генерирует следующий HTML-код на клиенте.
Я хочу сослаться на конкретный элемент управления RadioButton, используя JavaScript.
Я не уверен, как это сделать, так как идентификатор RadioButton генерируется asp.net.
Например, я даю идентификатор RadioButton = 1_RadioButton
asp.net генерирует ID = ctl00_ContentPlaceHolder1_Material_1_RadioButton
как этот код JavaScript может найти элементы управления Radio Button?
<script type="text/javascript">
$(document).ready(function() {
if (document.getElementById("1_RadioButton").checked) {
$("#1_other").hide();
}
});
</script>
Вот что asp.net генерирует для клиента.
<input id="ctl00_ContentPlaceHolder1_Material_1_RadioButton" type="radio" name="ctl00$ContentPlaceHolder1$Material$Academic" value="1_RadioButton" onclick="javascript:$('#1_other').show('fast');" />
<label for="ctl00_ContentPlaceHolder1_Material_1_RadioButton">Yes</label>
<input id="ctl00_ContentPlaceHolder1_Material_2_RadioButton" type="radio" name="ctl00$ContentPlaceHolder1$Material$Academic" value="2_RadioButton" checked="checked" onclick="javascript:$('#1_other').hide('fast');" />
<label for="ctl00_ContentPlaceHolder1_Material_2_RadioButton">No</label>
<input id="ctl00_ContentPlaceHolder1_Material_3_RadioButton" type="radio" name="ctl00$ContentPlaceHolder1$Material$Academic" value="3_RadioButton" onclick="javascript:$('#1_other').hide('fast');" />
<label for="ctl00_ContentPlaceHolder1_Material_3_RadioButton">Uncertain</label>
<div id='1_other'>
<input name="ctl00$ContentPlaceHolder1$Material$4_TextBox" type="text" value="bbb chabng" id="ctl00_ContentPlaceHolder1_Material_4_TextBox" />
</div>