获得多选元素的父TR

时间:2013-12-03 21:36:06

标签: jquery dom jquery-selectors

我有一个基于表格的表单,有两个多选控件(也在表中),基于ddl中的值,我想显示/隐藏包含多选控件的行。

然而,我发现我的代码只切换内表行。我真正喜欢的是外表的行被切换。我认为使用父母可能会工作,但事实并非如此。

BTW。我也试过了parent()。parent()。toggle(),但由于某种原因,它也没有用。

这是HTML

<table>
  <tr>
     <select> //numero
       <option>Uno</option>
       <option>Dos</option> 
     </select>
  </tr>
  <tr> <-- hide this row when Uno is chosen
     <table> //multi-select control table
    <tr></tr> <-- this is the row that is being hidden when i toggle() Uno
     </table>
  </tr>
  <tr> <-- another row i want to toggle when Dos is chosen
     <table> //multi-select control table
    <tr></tr> <-- this is the row that is being hidden when i toggle()
     </table>
  </tr>
</table>

这是我的jQuery

 $("select[title='Numero']").change(function(){
     $("select[title='hide this row']").closest("tr").next("tr").toggle();
     $("select[title='another row i want to toggle']").closest("tr").toggle();
 }); //close Numero.change()

非常感谢!

0 个答案:

没有答案
相关问题