jquery 操作两个select 来实现值之间的传递
2011-09-15 11:21
691 查看
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'); });
相关文章推荐
- 两个select之间option的互相添加操作(jquery实现)
- 两个select之间option的互相添加操作(jquery实现)
- jQuery获取Radio选择的Value值||两个select之间option的互相添加操作(jquery实现)
- Jquery实现两个select框中元素操作
- jQuery 两个select之间option的互相添加操作
- jquery 实现两个select之间option的转移
- jQuery实现两个select控件的互移操作
- jQuery实现两个CSS样式之间的点击切换
- Android成长之路-关于bundle实现两个activity之间的数据传递
- iOS开发中,实现两个控制器之间数据的双向传递
- Jquery操作radio,checkbox,select表单操作实现代码
- 用WM_COPYDATA消息来实现两个进程之间传递数据
- Jquery操作radio,checkbox,select表单操作实现代码
- jquery 实现对select操作的日期联动
- iOS实现两个控制器之间数据的双向传递
- 用WM_COPYDATA消息来实现两个进程之间传递数据