繁体   English   中英

这很丑陋,必须有更好的方法在jQuery中编写它

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM