これを使用して、複数の選択ボックスの値に応じてリストを作成しています。
$(document).ready(function() {
$("select").change(function() { // <-- bind change event handler to the drop downs
var sel = "";
$(".option-select option:selected").each(function() { // <-- then iterate each time it changes
if ($(this).index() !== 0) { // <-- only if not default
sel += "<li>" + $(this).text() + "</li>";
}
$("ul.result ul").empty().append(sel); //<-- empty() to remove old list and update with new list
});
});
});
ただし、リストに追加されたオプションの数、または値が選択された選択ボックスの数を出力する方法がわかりません。ユーザーが選択したオプションの数を、既に持っているようにそれらのオプションを表示するとともに、ユーザーに伝える必要があります。次を使用して、リスト内のアイテムの数を数える方法を見つけました。
var count = $("ul li").length;
しかし、このカウントを出力する方法がわかりません。