2011-08-02 34 views
5

我得到這個HTMLjQuery .nextAll不工作?

<tr> 
<td> 
Main Alliase/Current Alliase: 
</td> 
<td><input type="text" id="maina" class="countchars" max="30"/><br /> 
    <span class="showchars"></span> 
</td> 
<td><span id="handle-1" class="selector" title="The Main Alliase with which people know you OR the alliase with which u play most <br /> <b>You'r App would be also named after this only</b>" header="Main Alliase/Current Alliase">?</span></td> 
<td><div id="error-1" class="errors"></div></td> 
</tr> 

而且這個js:

$('#maina').focus(function() { 
$(this).closest("tr").find(".selector").qtip('toggle', true); 
    $(this).nextAll(".errors:first").html("Bla"); 
    $(this).siblings(".showchars").show(); 
}); 

但是當我聚焦到它的其它兩件事情,但犯規改變errors類的HTML的maina

爲什麼這麼說? 我一直在做錯什麼? 請幫我 感謝

回答

3

我認爲你應該做的:

$(this).closest('tr').find(".errors:first").html("Bla"); 

Yhis是因爲nextAll()尋找兄弟姐妹(Get all following siblings of each element in the set of matched elements, optionally filtered by a selector)和皮埃爾唯一的兄弟是跨度

+0

我試過,但有一點變化我在地方的「TR」 – kritya

+0

推杆「格」如果你使用TR你一定會得到與類錯誤的DIV同一行 –

+0

但爲什麼不能給我同樣的結果? – kritya

1

由於你可以看到this example.nextAll()只給你回兄弟姐妹。

你可以使用:

$(this).parents("tr").eq(0).find(".errors:eq(0)").html("Bla");