应用场景——双盒选择器

 

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();
    }

相关文章:

  • 2021-07-05
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-07
  • 2021-12-03
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
相关资源
相似解决方案