jquery 操作两个select实现值之间的互相传递
function moveToRight(select1,select2)//把选中的移动到右边 sleect1和sleect2分别是下拉列表框的ID
{
$('#'+select1+' option:selected').each(function(){
$("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select2+"");
$(this).remove();
$('#'+select2).bind('dblclick',function(){
moveToLeft(select1,select2);
});
});
}
function moveAllToRight(select1,select2)//把所有的移动到右边
{
$('#'+select1+' option').each(function(){
$("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select2+"");
$(this).remove();
});
}
function moveToLeft(select1,select2)//把选中的移动到左边
{
$('#'+select2+' option:selected').each(function(){
$("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select1+"");
$(this).remove();
});
}
function moveAllToLeft(select1,select2)//把所有的移动到左边
{
$('#'+select2+' option').each(function(){
$("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select1+"");
$(this).remove();
});
}
如果要双击select中的某一个option就把当前值传到另一个select需要bind一个select 事件 如下即可
$('#sel2').bind('dblclick',function(){//给下拉框绑定双击事件
moveToRight('sel2','sel3');
});
$('#sel3').bind('dblclick',function(){
moveToLeft('sel2','sel3');
});
您可能感兴趣的文章:
jquery 操作两个select实现值之间的互相传递
Vue.jS的ul-li标签仿select标签
php值传递和引用传递的区别是什么?
JS父子窗口相互取值与赋值的方法参考
解析jquery获取父窗口的元素
Go 语言函数值传递值
php优化方法
jQuery UI 通过部件库扩展小部件
提高PHP性能效率的几个技巧
浅析jQuery(function(){})与(function(){})(jQuery)之间的区别