javascript - 生成的单选按钮选项卡

标签 javascript c# html .net user-experience

我似乎无法让我的单选按钮允许在下表中导航。表格本身甚至不使用选项卡按钮进行选择,但页面上的所有其他元素都可以。单选按钮和表格行是通过循环生成的。有没有办法让选项卡按钮选择表格,然后通过单选按钮导航?如果您需要更多信息,请告诉我。

网页:

<%-- Loop through all managers and write the radio button options --%>
 <%int managerIndex = 1; %>
   <%foreach (Manager manager in Managers) %>
            <%{ %>
                <%string responseValue = x;%>
                    <td>
                        <table id='RadioButtonList<%=managerIndex %>' border="0" style="height:25px">
                    <%=HtmlHelper.GetRadioButtonGroupHtml("Radio" + managerIndex, item.SurveyQuestionID, manager.ManagerID, manager.ManagerRoleID, rowClass, "radioList1", responseValue)%>
                        </table>
                    </td>
                <%managerIndex++; %>
            <%} %>
            </tr>

隐藏代码:

StringBuilder html = new StringBuilder();

html.Append("<tr>");

// create a hidden blank value that is checked by default
html.Append(String.Format("<td style=\"display:none\"><input id=\"{0}\" type=\"radio\" name=\"ctl_QID{1}_MID{2}\" value=\"{3}\" checked/><label for=\"{4}\"></label></td>", id + 0, questionId, managerId, "", group));

// create the radio buttons for the values of 1-5
for (int i = 1; i <= 5; i++)
{
    // set the button to 'checked' if the response value matches
    if (i.ToString() == responseValue)
        html.Append(String.Format("<td style=\"width:30px\"><input id=\"{0}\" type=\"radio\" name=\"ctl_QID{1}_MID{2}\" value=\"{3}\" checked/><label for=\"{4}\"></label></td>", id + i, questionId, managerId, i, group));
    else
        html.Append(String.Format("<td style=\"width:30px\"><input id=\"{0}\" type=\"radio\" name=\"ctl_QID{1}_MID{2}\" value=\"{3}\" /><label for=\"{4}\"></label></td>", id + i, questionId, managerId, i, group));
}

// create the N/R radio button and set it to 'checked' if necessary
if (responseValue == "NA")
    html.Append(String.Format("<td style=\"width:30px; background-color: #798d8f; text-align: center;\"><input id=\"{0}\" type=\"radio\" name=\"ctl_QID{1}_MID{2}\" value=\"{3}\" checked/><label for=\"{4}\"></label></td>", id + 6, questionId, managerId, "NA", group));
else
    html.Append(String.Format("<td style=\"width:30px; background-color: #798d8f; text-align: center;\"><input id=\"{0}\" type=\"radio\" name=\"ctl_QID{1}_MID{2}\" value=\"{3}\" /><label for=\"{4}\"></label></td>", id + 6, questionId, managerId, "NA", group));

// append the closing <tr> tag
html.Append("</tr>");
return html.ToString();

最佳答案

您可以添加tabindex属性 - tabindex="0" 到您的输入单选元素。它们将通过使用 Tab 键(按照它们在源中的顺序)进行聚焦。

0索引是一个特殊索引。来自 MDN:

tabindex="0" means that the element should be focusable in sequential keyboard navigation, but its order is defined by the document's source order.

如果您愿意,也可以通过更改索引值来使用不同的顺序。

关于javascript - 生成的单选按钮选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51882415/

相关文章:

c# - 显示 SSN 的最后四位数字

javascript - Angular 服务不在 Controller 之间传递

javascript - 多个页面上的html的静态部分

javascript - 如何设置特定类紧随另一个跨度之后的跨度的样式

c# - 在 C# 中使用 Action<T> 作为参数(模仿函数指针)

c# - 设置EF拦截器文件名布局

html - 页面高度的 100% 应用程序主屏幕 CSS

html - 为什么我不能输入或点击文本区域?

javascript - Gallery Filters,如何在这个例子中使用?

javascript:获取伪高度:元素之前