简体   繁体   English

在jQuery中选择下一个SELECT

[英]Selecting next SELECT in jQuery

jQuery jQuery的

$("select[id^='_taskAssignedTo_']").each(function(id) {
    if ($(this).val() == "1") {
        $(this).next().find("select[id^='_taskStatus_']").prop("disabled", false);
    }
});

HTML HTML

<td>
    <select id="_taskAssignedTo_1"> <!-- options --> </select>
<td>
<td>
    <select id="_taskStatus_1"> <!-- options --> </select>
<td>

I am looping through and finding the first select because it has the value I need to search for and I want to enable the select next to it called, _taskStatus_1 . 我正在遍历并找到第一个select因为它具有我需要搜索的值,并且我想启用它旁边的select ,即_taskStatus_1 There are many, so it is important I use the "start with" syntax. 有很多,因此使用“开始于”语法非常重要。

The code above does not work. 上面的代码不起作用。 I am not sure if I need to use next , find , something else, or a combination? 我不确定是否需要使用nextfind ,其他方式或组合方式?

Just do: 做就是了:

$(this).closest("td").next("td").find("select[id^='_taskStatus_']");

You have to first travel back to your td (closest) - then to the next td (next) - then find the element you're looking for. 您必须先返回到td (最近的位置),然后再返回到下一个td (下一个),然后find所需的元素。

尝试:

$(this).parent().next().find("select[id^='_taskStatus_']").prop("disabled", false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM