在 jQuery 中获取 .each 循环中选定的子项

发布于 2024-09-15 10:03:53 字数 249 浏览 2 评论 0原文

嘿伙计们。我试图在每个循环中获取选定的选项。实现这一目标的正确语法是什么?

我尝试了以下方法:

var row = $('#template_23423);

row.find('select[name^=COUNTY]').each(function (){
    var selectedOption = $(this).children(':selected').val();

有什么想法吗?

Hey guys. I am trying to get the selected option in an each loop. What is the correct syntax to achieve that?

I tried the following:

var row = $('#template_23423);

row.find('select[name^=COUNTY]').each(function (){
    var selectedOption = $(this).children(':selected').val();

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巾帼英雄 2024-09-22 10:03:53
var row = $('#template_23423');

row.find('select[name^=COUNTY]').each(function(){
  var selectedOption = $('option:selected', $(this)).val();
};

这将为您提供 options 的值,如果您想要它们的文本,请使用 text() 而不是 val()

var row = $('#template_23423');

row.find('select[name^=COUNTY]').each(function(){
  var selectedOption = $('option:selected', $(this)).val();
};

That will give you the value of the options if you want to their text, use text() instead of val().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文