选择/选项的jQuery选择器:已选中 [英] jQuery selectors for select / option:selected

查看:59
本文介绍了选择/选项的jQuery选择器:已选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何理解

$("select option:selected")

在以下代码中?

(取自这里

$("select").change(function() {
   ...
   $("select option:selected").each(function () {
      ...
   });
   ...
})

是否所有选择的选项文件中的全部选择

Is it all selected options in all selects in the document ?

它是否与当前选择相关,$(this)?

Is it somehow related to the current select, $(this) ?

推荐答案

是的,它将引用所有选择中的所有选定选项。如果您只想查看当前选择,您可以执行以下操作:

Yes, it will refer to all selected options in all selects. If you just want to look at the current select, you can do something like this:

$("select").change(function() {
   ...
   $(this).find("option:selected").each(function () {
      ...
   });
   ...
})

这篇关于选择/选项的jQuery选择器:已选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆