![](/img/trans.png)
[英]jQuery selector for finding the first element after a given element that matches a selector
[英]Finding the next type of element after a selector in jquery
我希望在找到以特定方式結束的圖像后找到下一種元素類型方面的幫助。 到目前為止,我已經找到了圖像並開始運行 each() function,但我無法將其轉到頁面上的下一個輸入 select。
這是我到目前為止的代碼:
$("img[src$='sunglasses.jpg']").each(function( index ) {
$( this ).closest(".label_box").find("input[name^=happy_]").prop('value', '1');
$( this ).nextAll("input[name^=happy_").eq(0).prop('value', '1');
});
HTML 的示例如下所示:
<div class="image_box">
<img src="sunglasses.jpg">
</div>
<div class="label_box">
<input name="happy_1">
</div>
本質上,我試圖在找到匹配圖像后直接在另一個 div 中輸入 happy_* select。
沒關系,我想通了。 我只需要添加 2.parent() 函數來獲得正確的 div。
$(this).parent().parent().next('div').find("input[name^=happy_]")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.