[英]jQuery - selectors and $(this)
Ok this is a general question about how to solve this issue, not to find some work around for the example given. 好的,这是一个有关如何解决此问题的一般性问题,而不是为给出的示例找到解决方法。
Lets say I have a $(this)
object and it is a select
, if I want to select the selected option and I had an id
I could just bust a 可以说我有一个$(this)
对象,它是一个select
,如果我想选择选中的选项,并且我有一个id
我就可以破坏一个
$('#id option:selected')
game over. 游戏结束。
but with a this
I can't go $(this+' option:selected')
or anything like that. 但是有了this
我不能去$(this+' option:selected')
或类似的东西。
I am not so concerned with selecting the option:selected
in the example so I don't want to know a workaround solution for this instance. 我不太关心在示例中选择option:selected
,所以我不想知道此实例的解决方法。
What I want to know is in general how you combine the subselectors like :has
or option:selected
with a $(this)
situation. 我想知道的是一般如何将$(this)
:has
或option:selected
与$(this)
情况组合。
Thanks. 谢谢。
通过使用可选的context参数 :
$('option:selected', this)
您也可以这样做:
$(this).find('option:selected');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.