Jquery 获取mutli select元素的父TR
我有一个基于表的表单,有两个多选控件(也在表中),基于ddl中的值,我想显示/隐藏包含多选控件的行 但是,我发现我的代码只切换内部表行。我真正想要的是切换外部表的行。我认为使用家长可能有效,但没有 顺便说一句,我也尝试了parent().parent().toggle(),但由于某种原因,它也不起作用 这是HTMLJquery 获取mutli select元素的父TR,jquery,dom,jquery-selectors,Jquery,Dom,Jquery Selectors,我有一个基于表的表单,有两个多选控件(也在表中),基于ddl中的值,我想显示/隐藏包含多选控件的行 但是,我发现我的代码只切换内部表行。我真正想要的是切换外部表的行。我认为使用家长可能有效,但没有 顺便说一句,我也尝试了parent().parent().toggle(),但由于某种原因,它也不起作用 这是HTML <table> <tr> <select> //numero <option>Uno</option
<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>
非常感谢 你能提供你真正的html吗?你能给我们一个更完整的html例子吗?您的选择器与任何元素都不匹配,并且我在跟随注释和箭头时遇到问题。我建议在您要切换的行上放置一个类,以使选择它们更容易。j08691,我不能使用类,b/c SharePoint正在生成html代码。这是我的建议:
$("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()