我有工作jQuery是添加一个计数取决于选定项目的数量,问题是我有多个选择器和多个计数显示字段。我不太清楚为什么这不起作用。jQuery .on()函数不能按预期工作
当我改变1选择它改变所有选择的计数。
/*Account Group Count*/
$('body').on('change', $('#group-accounts'),function() {
var strAccount = $("select option:selected").length;
$(".AccountCount").text(strAccount);
$(".AccountSmallCount").text(strAccount + ' selected');
});
/*User Group Count*/
$('body').on('change', $('#group-users'),function() {
var strUser = $("select option:selected").length;
$(".UsersCount").text(strUser);
$(".UsersSmallCount").text(strUser + ' selected');
});
这里是选择之一
<div class="ui-multiselect col-full group-accounts-select">
<select name="group-accounts" id="group-accounts" multiple>
<cfloop query="AccountGroupList">
<option value="<cfoutput>#AccountGroupList.aprimID#</cfoutput>"><cfoutput>#aName#</cfoutput></option>
</cfloop>
</select>
<label for="group-accounts"><span>Accounts:</span></label>
</div>
<span class="AccountSmallCount"></span>
请提供[MCVE] –
为什么你传递jQuery对象,而不是只是选择器? –
在做出这样简单的基本错误之前,请先阅读API。 – vsync