js 解决 select option 过多 ,筛选过滤功能
lxq73061:
如果option非常 多上千个,这个代码会非常 卡。
可以参考以下代码优化
如果option非常 多上千个,这个代码会非常 卡。
可以参考以下代码优化
[code=javascript]
var select_filter_data={};
$(document).on('keyup','.select_filter',function(){
$(this).change();
});
$(document).on('change','.select_filter',function(){
var v=$.trim($(this).val());
var name=$(this).attr('name').replace('_filter','');
var obj = $(this).parent().find('select[name="'+name+'"]');
if(!obj.size()){
var obj = $(this).parent().find('select[name="'+name+'[]"]');
}
if(!obj.size()){
var obj = $('select[name="'+name+'"]');
}
if(!select_filter_data[name]){
select_filter_data[name]={};
$(obj).find('option').each(function(){
select_filter_data[name][$(this).val()]=$(this).text();
});
console.log('init select_filter '+name);
[/code]
|