下拉框去除重复内容
<script type="text/javascript" src="http://www.joleye.com/libraries/javascript/jquery-1.5.1.min.js"></script> <a href="###">加载</a> <select> </select> <a href="###">加载</a> <select> </select> <a href="###">加载</a> <select> </select> <a href="###">加载</a> <select> </select> <a href="###">加载</a> <select> </select> <a href="###">加载</a> <select> </select> <script> var option = [ { value : ‘‘, text : ‘--请选择--‘ }, { value : ‘1‘, text : ‘java‘ }, { value : ‘2‘, text : ‘.net‘ }, { value : ‘3‘, text : ‘python‘ } ]; $(‘a‘).click(function(){ var t = $(this).next(); if(t.val()!=null){ t.empty(); } var tar = {}; $(‘select option:selected‘).each(function(){ if($(this).val() != ‘‘) tar[$(this).val()] = 1; }); var newoption = []; $.each(option,function(i,val){ if(!tar[val.value]){ newoption.push(val); } }); $.each(newoption,function(i,val){ $(‘<option value="‘+val.value+‘">‘+val.text+‘</option>‘).appendTo(t); }); }); </script>
演示地址:http://jsfiddle.net/joleye/cxzxm8so/
时间: 2024-10-27 12:41:03