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

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

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

function moveToRight(select1,select2)//把選中的移動(dòng)到右邊 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)//把所有的移動(dòng)到右邊
{
 $('#'+select1+' option').each(function(){
  $("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select2+"");
  $(this).remove();
 });
}
function moveToLeft(select1,select2)//把選中的移動(dòng)到左邊
{
 $('#'+select2+' option:selected').each(function(){
  $("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select1+"");
  $(this).remove();
 });
}
function moveAllToLeft(select1,select2)//把所有的移動(dòng)到左邊
{
 $('#'+select2+' option').each(function(){
  $("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo("#"+select1+"");
  $(this).remove();
 });
}

如果要雙擊select中的某一個(gè)option就把當(dāng)前值傳到另一個(gè)select需要bind一個(gè)select 事件 如下即可
復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評(píng)論