首页 > Web开发 > 详细

jquery 排除重复

时间:2015-09-23 14:46:59      阅读:246      评论:0      收藏:0      [点我收藏+]

应用场景——双盒选择器

 

技术分享

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

jquery 排除重复

原文:http://www.cnblogs.com/winkey4986/p/4832126.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!