Как получить текст радиокнопки, которая динамически создается на C #, в Javascript? - PullRequest
0 голосов
/ 26 февраля 2019

Я добавляю радиокнопки на свою HTML-страницу динамически с помощью C # с помощью:

for (int i = 0; i < groupnames.Count; i++)
{
    HtmlTableRow row = new HtmlTableRow();
    HtmlTableCell cell = new HtmlTableCell();
    RadioButton radioButton = new RadioButton();
    radioButton.ID = "rdDataGroup_" + i;
    radioButton.Text = groupnames[i].GroupName;
    radioButton.GroupName = "DataGroup";
    if (i==0)
    {
       radioButton.Checked = true;
    }
    cell.Controls.Add(radioButton);
    row.Cells.Add(cell);
    tblRadioButtonList.Rows.Add(row);
}

Когда я проверяю свои радиокнопки в веб-браузере (F12), я вижу следующее:

enter image description here

Моя проблема в том, что мне не удалось добраться до текста радиокнопок (-ок) в javascript.Где находится атрибут Text?Как мне получить текст в JS или JQuery?Я попытался предупредить тех, кто ниже, ни один из них не сработал.

document.getElementById("rdDataGroup_1").InnerHTML; //returns empty string
document.getElementById("rdDataGroup_1").InnerText; //returns empty string
document.getElementById("rdDataGroup_1").value; //returns id
$("input[name='DataGroup']:checked").data('name'); //undefined
$("input[name='DataGroup']:checked").parent('label').text(); //returns empty string

Любая помощь будет оценена.

Редактировать: Я уверен, что имена групп [i] .GroupName не является пустой строкой.

Edit2: только что попробовал $("input[name='DataGroup']:checked").parent().text();, и он вернул текст выбранной кнопки радио.Все еще не уверены, почему innerhtml или innertext (также .value) не работают, но jquery помог.

Edit3: HTML следует:

<body>
    <form id="myForm" runat="server">
        <section class="container">
            <div class="row">
                <div class="col-lg-3">
                    <table id="tblRadioButtonList" runat="server"></table>
                    <div id="divFinding"></div>
                    <div id="divUnderstood"></div>
                    <div id="divImpactful"></div>
                </div>
            </div>

        </section>
   <form>
<body>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...