手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >jquery 操作两个select实现值之间的互相传递
jquery 操作两个select实现值之间的互相传递
摘要:复制代码代码如下:functionmoveToRight(select1,select2)//把选中的移动到右边sleect1和sleect...

复制代码 代码如下:

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实现值之间的互相传递】相关文章:

jQuery判断一个元素是否可见的方法

jQuery获取字符串中出现最多的数

jQuery插件实现适用于移动端的地址选择器

jQuery实现转动随机数抽奖效果的方法

jQuery仿gmail实现fixed布局的方法

Jquery实现动态切换图片的方法

jQuery实现弹出窗口中切换登录与注册表单

javascript实现炫酷的拖动分页

jquery实现图片左右切换的方法

jQuery实现返回顶部效果的方法

精品推荐
分类导航