源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

jquery 操作两个select实现值之间的互相传递

  • 时间:2020-11-20 10:30 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:jquery 操作两个select实现值之间的互相传递
[u]复制代码[/u] 代码如下:
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 事件 如下即可
[u]复制代码[/u] 代码如下:
$('#sel2').bind('dblclick',function(){//给下拉框绑定双击事件      moveToRight('sel2','sel3');     });     $('#sel3').bind('dblclick',function(){      moveToLeft('sel2','sel3');     }); 
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部