$(this).closest(("选择[name * =' FIELD2']")不工作

时间:2014-03-16 22:17:23

标签: javascript jquery dom

我有这样的表格:

<div id="div_id_form-0-FIELD1" class="form-group">
  <label for="id_form-0-FIELD1" class="control-label col-sm-2">
    Amount Type
  </label>
  <div class="controls col-sm-3">
    <select class="select form-control" id="id_form-0-FIELD1" name="form-0-FIELD1">
      <option value="">---------</option>
      <option value="d" selected="selected">Dollars</option>
      <option value="p">Percent of</option>
    </select>
  </div>
</div>
<div id="div_id_form-0-FIELD2" class="form-group">
  <label for="id_form-0-FIELD2" class="control-label col-sm-2">
    Deduct from total
  </label>
  <div class="controls col-sm-3">
    <select class="select form-control" id="id_form-0-FIELD2" name="form-0-FIELD2">
      <option value="" selected="selected">---------</option>
      <option value="g">Gross Pay</option>
      <option value="n">Net Pay</option>
      <option value="h">Hourly Rate</option>
    </select>
  </div>
</div>

FIELD1中有($this),我想获得FIELD2。这不适合我:

$(this).closest(("select[name*='FIELD2']")

1 个答案:

答案 0 :(得分:0)

使用.next()方法,如下所示:

$(this)
    .closest("div.form-group")
    .next("div.form-group")
         .find("select[name*='FIELD2']");