2011-02-10 32 views
0

我使用下拉選擇器將外部文件中的匹配部分加載到選擇器下面一行中的表格單元格中。我似乎無法正確定位它。我認爲nextAll()會做的,但事實並非如此。我還有什麼可以嘗試的?用jQuery加載到合適的孩子中

$('.mySelector').change(function(){ 
    var $selectForm = '#' + $(this).val(); 
    $(this).nextAll('.fLoad').load('formParts.html ' + $selectForm); 
}); 

<table> 
<tr> 
    <td> 
    <select class="mySelector"> 
     <option value="o1">Car details</option> 
     <option value="o2">Bike details</option> 
     <option value="o3">Boat details</option> 
    </select> 
    </td> 
</tr> 
<tr> 
    <td class='fLoad'>&nbsp;</td> 
</tr> 
<tr> 
    <td> 
    <select class="mySelector"> 
     <option value="o1">Car details</option> 
     <option value="o2">Bike details</option> 
     <option value="o3">Boat details</option> 
    </select> 
    </td> 
</tr> 
<tr> 
    <td class='fLoad'>&nbsp;</td> 
</tr> 
</table> 
+0

您需要確定負載發生故障的DOM遍歷。將該行更改爲`$(this).nextAll('。fLoad')。text('found it')`以檢查您是否找到了正確的元素。 – 2011-02-10 14:28:46

+0

不,它似乎並不像它發現的目標... – santa 2011-02-10 14:43:11

回答

2

這樣做:

$(this).closest('tr').next().find('.fLoad').load('formParts.html ' + $selectForm);