[英]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]');
Thats just stupid looking, but its the best way i can think of writing it. 多数民众赞成看起来很愚蠢,但这是我能想到的最佳方式。 I tried
parentsUntil('li')
but that didnt work at all and i also tried parents('li')
and closest('li')
. 我尝试过
parentsUntil('li')
但那根本没有用,我也试过parents('li')
和closest('li')
。 Isnt there something in jQuery with the equivalent of: 在jQuery中有什么东西相当于:
$(this).firstParentThatMatchesThis('li').find('[name=reply_to_id]');
If not i think ill try submitting it to the jQuery core... 如果不是我认为生病尝试将其提交给jQuery核心...
Here is my HTML (long so i put it on pastebin): http://pastebin.com/FypJ9WGe 这是我的HTML(很长时间我把它放在pastebin上): http : //pastebin.com/FypJ9WGe
Working on getting JSFiddle in there... 努力让JSFiddle进入那里......
Try this: 试试这个:
$(this).parents("li").eq(0).find('[name=reply_to_id]');
Example: http://jsfiddle.net/FvzT9/ 示例: http : //jsfiddle.net/FvzT9/
But, closest
should work as well: 但是,
closest
应该有效:
$(this).closest("li").find('[name=reply_to_id]');
Example: http://jsfiddle.net/FvzT9/1/ 示例: http : //jsfiddle.net/FvzT9/1/
$(this).closest('li').find('[name=reply_to_id]');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.