如何使用 jquery 获取下一个相对下拉列表
我有这个代码
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
.nextAll()
和:first
像这样:因为它们是兄弟姐妹,所以使用
.nextAll()
遍历所有同级,并且您想要第一个You can do it using
.nextAll()
and:first
like this: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.