我使用取决于多重选择框的值,这个填充列表:追加列表项目计数的jQuery
$(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;
但无法弄清楚如何打印此计数。