如何使JavaScript只在特定的DIV标记中起作用

How to make JavaScript count only in a specific DIV tag

本文关键字:DIV 起作用 JavaScript 何使      更新时间:2024-05-20

我有这样的代码,它计算所选的等于5的选择框。我如何只计算中的选择

<div id="groupa">

这是我的代码

function getSelectedValues(){
var matches = $('select').filter(function(){
return $(this).val() == '5';
}).length;
// here's where we just update that new <span>
$('span#result5').text(matches);
}

更改选择器

function getSelectedValues(){
var matches = $('#groupa select').filter(function(){
return $(this).val() == '5';
}).length;
// here's where we just update that new <span>
$('span#result5').text(matches);
}