Loading

两个select一个选中,另一个就没有选中的那个值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>若水demo</title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
</head>
<body>
    <select name="" id="" class="prientity_type">
        <option value="0">1</option><!-- 显示的值比value的值大1 -->
    </select>
    <select name="" id="" class="prientity_type">
        <option value="1">2</option>
    </select>
    <script>
        $(function(){
            
           var prientity_type = "0,1,2,3,4,5,6";//后台传过来的
           var prientity_type_value = prientity_type.split(',');
           var prientity_type1_obj = $(".prientity_type").eq(0);
           var prientity_type2_obj = $(".prientity_type").eq(1);
           function rs_change(){
               var prientity_type1_key = prientity_type1_obj.val();
               var prientity_type2_key = prientity_type2_obj.val();
               var prientity_type1_html = '';
               var prientity_type2_html = '';
               $.each(prientity_type_value,function(n,v){
                       if(v != prientity_type2_key){
                           prientity_type1_html += '<option value="'+v+'">'+(parseInt(v)+1)+'</option>';
                       }
                       if(v != prientity_type1_key){
                           prientity_type2_html += '<option value="'+v+'">'+(parseInt(v)+1)+'</option>';
                       }
               });
               prientity_type1_obj.empty().append(prientity_type1_html).val(prientity_type1_key);
               prientity_type2_obj.empty().append(prientity_type2_html).val(prientity_type2_key);
            }
           prientity_type1_obj.change(function(){
                   rs_change();
           });
           prientity_type2_obj.change(function(){
                   rs_change();
           });
           rs_change();
        });
    </script>
</body>
</html>

 

posted @ 2017-09-05 16:59  王召波  阅读(1515)  评论(0编辑  收藏  举报