是否可以在多个选择下拉列表中设置限制? [英] Is it possible to set limit in multiple selection dropdown list?
本文介绍了是否可以在多个选择下拉列表中设置限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的网站上使用了一个多选下拉列表,这可以正常工作,我们可以从该列表中选择多个选项,但是我只想从该列表中选择3个选项,是否可以设置限制为此吗?
I am using a multiple selection drop-down list in my site.This is working properly and we can select more than one options from that list.But I want select only 3 options from that list.Is it possible to set limit for that??
我正在使用 http://www.aleixcortadellas.com上的代码/main/2009/03/20/492/
推荐答案
使用 jQuery 并遵循 click 函数,它将有所帮助
use jQuery and following click function, it will help
$(document).ready(function()
{
$('#slectboxid option').click(function()
{
var items = $(this).parent().val();
if (items.length > 3) {
alert("You can only select 3 values at a time");
$(this).removeAttr("selected");
}
});
});
编辑:使用.prop()
代替.removeAttr()
,.removeAttr()
在最新的jQuery库中已弃用
Edit: use .prop()
instead of .removeAttr()
,.removeAttr()
is deprecated in newest jQuery libraries
这篇关于是否可以在多个选择下拉列表中设置限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文