zoukankan      html  css  js  c++  java
  • jquery 排除重复

    应用场景——双盒选择器

    两个select可能会出现重复的情况

    排除重复代码如下:

    /**
         * 删除$fromGroup中与$toGroup重复的option
         * @param $fromGroup = $('#' + fromGroup + ' option:selected')
         * @param $toGroup = $('#' + toGroup + ' option')
         */
        function filterRepeat($fromGroup, $toGroup) {
            //方法一:
            /*var repeatItems = $.grep($fromGroup, function(v){
                // if the item does not exist return true which includes it in the new array
                return $toGroup.filter("option[value='" + $(v).val() + "']").length != 0;
            });*/
            //方法二:
            var repeatItems = $fromGroup.filter(function(index){
                return $toGroup.filter("option[value='" + $(this).val() + "']").length != 0;
             });
            $(repeatItems).remove();
        }
  • 相关阅读:
    bzoj1711
    bzoj1458
    bzoj1433
    hdu2732
    bzoj1066
    hdu3549
    poj1698
    [ZJOI2007]时态同步
    SA 学习笔记
    [LUOGU]2016 Sam数
  • 原文地址:https://www.cnblogs.com/winkey4986/p/4832126.html
Copyright © 2011-2022 走看看