[英]This is ugly and there has to be a better way to write it in jQuery
$(this).parent().parent().parent().parent().find('[name=reply_to_id]');
多數民眾贊成看起來很愚蠢,但這是我能想到的最佳方式。 我嘗試過parentsUntil('li')
但那根本沒有用,我也試過parents('li')
和closest('li')
。 在jQuery中有什么東西相當於:
$(this).firstParentThatMatchesThis('li').find('[name=reply_to_id]');
如果不是我認為生病嘗試將其提交給jQuery核心...
這是我的HTML(很長時間我把它放在pastebin上): http : //pastebin.com/FypJ9WGe
努力讓JSFiddle進入那里......
試試這個:
$(this).parents("li").eq(0).find('[name=reply_to_id]');
示例: http : //jsfiddle.net/FvzT9/
但是, closest
應該有效:
$(this).closest("li").find('[name=reply_to_id]');
示例: http : //jsfiddle.net/FvzT9/1/
$(this).closest('li').find('[name=reply_to_id]');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.