我正在使用 Jquery 和 html,我刚刚遇到了列表菜单(多个)验证的问题。问题是我无法(/不知道如何)计算用户所做的选择数量。我尝试在每个选项值的末尾添加“:”,然后将文本拆分为一个数组,它确实有效,但后来我弄乱了我的数据库。
var int_country= $('#int_country :selected').text();
listLength = int_country.split(":");
if (listLength.length > 16){
var i = listLength.length -1;
alert ("You have selected " + i + " countries. \nPlease select 15 or less international countries!");
$('#int_country').focus();
return false;
}
有什么建议可以解决这个问题吗?
最佳答案
$('#int_country :selected').length
获取计数
关于jquery 列表框验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1240608/