如何使JavaScript仅在特定的DIV标记中计数

时间:2015-02-24 18:29:14

标签: javascript

我有这个代码,它会选择等于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);
}

1 个答案:

答案 0 :(得分:0)

更改选择器

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);
}