欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery 操作兩個select實現(xiàn)值之間的互相傳遞

 更新時間:2014年03月07日 09:04:07   作者:  
本篇文章主要是對jquery操作兩個select實現(xiàn)值之間的互相傳遞進行了詳細的介紹,需要的朋友可以過來參考下,希望對大家有所幫助
復(fù)制代碼 代碼如下:

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 事件 如下即可
復(fù)制代碼 代碼如下:

$('#sel2').bind('dblclick',function(){//給下拉框綁定雙擊事件
     moveToRight('sel2','sel3');
    });
    $('#sel3').bind('dblclick',function(){
     moveToLeft('sel2','sel3');
    }); 

相關(guān)文章

最新評論