如何使用 jquery 获取下一个相对下拉列表

发布于 2024-09-16 13:41:53 字数 1320 浏览 2 评论 0原文

我有这个代码

<div id="aggregate" style="display:inline">
                    <%=Html.RadioButton("a", "1", true, new {id = "meRadio"})%><label>Me</label>
                    <%=Html.RadioButton("a", "2", false, new { id = "teamRadio" })%><label>Team: </label><% = Html.DropDownList("Teams", Model.Teams,  new {@scope="Team",  @id = "teamDropdown", @class = "filterDropdown" })%>
                    <%=Html.RadioButton("a", "4", false, new { id = "managerRadio" })%><label>Manager: </label><% = Html.DropDownList("Managers", Model.People, new { @scope = "Manager", @id = "managerDropdown", @class = "filterDropdown" })%>
                    <%=Html.RadioButton("a", "5", false, new { id = "locationRadio" })%><label>Location: </label><% = Html.DropDownList("Locations", Model.Locations, new { @scope = "Location", @id = "locationDropdown", @class = "filterDropdown" })%>
  </div>

我目前有这样的代码:

 $('#workstreamRadio').click(function () {
     Enable("#workstreamDropdown");
 });

 $('#teamRadio').click(function () {
     Enable("#teamDropdown");
 });

我确信有一种方法使用 jquery 动态获取相应的下拉选择器,因为单击了特定的单选按钮,所以我不必对每个映射进行硬编码。

“让我选择我单击的单选按钮右侧的下拉列表的选择器”的语法是什么

i have this code

<div id="aggregate" style="display:inline">
                    <%=Html.RadioButton("a", "1", true, new {id = "meRadio"})%><label>Me</label>
                    <%=Html.RadioButton("a", "2", false, new { id = "teamRadio" })%><label>Team: </label><% = Html.DropDownList("Teams", Model.Teams,  new {@scope="Team",  @id = "teamDropdown", @class = "filterDropdown" })%>
                    <%=Html.RadioButton("a", "4", false, new { id = "managerRadio" })%><label>Manager: </label><% = Html.DropDownList("Managers", Model.People, new { @scope = "Manager", @id = "managerDropdown", @class = "filterDropdown" })%>
                    <%=Html.RadioButton("a", "5", false, new { id = "locationRadio" })%><label>Location: </label><% = Html.DropDownList("Locations", Model.Locations, new { @scope = "Location", @id = "locationDropdown", @class = "filterDropdown" })%>
  </div>

i currently have code like this:

 $('#workstreamRadio').click(function () {
     Enable("#workstreamDropdown");
 });

 $('#teamRadio').click(function () {
     Enable("#teamDropdown");
 });

I am sure there is a way using jquery to dynamically get the respective dropdown selector given a specific radio button clicked so i dont have to hard code each mapping.

what is the syntax for saying "get me the selector of the dropdown to the right of the radio button i clicked"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒尘 2024-09-23 13:41:53

您可以使用 .nextAll():first 像这样:

$("#aggregate :radio").change(function() {
  var dropdown = $(this).nextAll("select:first");
  //enable or disable dropdown
});

因为它们是兄弟姐妹,所以使用 .nextAll() 遍历所有同级,并且您想要第一个

You can do it using .nextAll() and :first like this:

$("#aggregate :radio").change(function() {
  var dropdown = $(this).nextAll("select:first");
  //enable or disable dropdown
});

since they're siblings, use .nextAll() which goes through all siblings, and you want the first <select> element, so select that from the siblings after the radio clicked. Also look at using .change() here instead of .click(), it'll fire only when the selection changes, which is usually what you want here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文