确保下拉菜单中使用了所有值 [英] Make sure all values are used in drop downs

查看:70
本文介绍了确保下拉菜单中使用了所有值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个<select>框,它们的值相同:

I have 4 <select> boxes with the same values:

  • 1
  • 2
  • 3
  • 4

我希望确保下拉列表中使用了每个值,且没有重复.

I wish to make sure each of these values are used in the dropdowns, with no duplicates.

我无法解决这个问题.我尝试循环选择框并挑选出值,但可能无法正常工作.有人对此有快速解决方案吗?

I can not get my head around this. I have tried looping the select boxes and picking out the values, but I can not get it to work probably. Does anyone have a quick-n-easy solution to this?

推荐答案

获取唯一值列表,然后使用原始数组检查长度.

Get the unique value list then check the length with the original array.

var arr = [1,2,3,4];

if ($.unique($('select').map(function(){ return $(this).val(); })).length === arr.length) {
   // OK
}

这篇关于确保下拉菜单中使用了所有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆