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