Home  >  Article  >  Web Front-end  >  jquery operates two selects to transfer values ​​to each other_jquery

jquery operates two selects to transfer values ​​to each other_jquery

WBOY
WBOYOriginal
2016-05-16 16:56:281067browse
Copy code The code is as follows:

function moveToRight(select1,select2)//Move the selected one to the right sleect1 and sleect2 are the IDs of the drop-down list box respectively
{
$('#' select1 ' option:selected').each(function(){
$("").appendTo("#" select2 "");
$(this).remove() ;
$('#' select2).bind('dblclick',function(){
moveToLeft(select1,select2);
});
});
}
function moveAllToRight(select1,select2)//Move all to the right
{
$('#' select1 ' option').each(function(){
$("").appendTo("#" select2 "");
$(this) .remove();
});
}
function moveToLeft(select1,select2)//Move the selected one to the left
{
$('#' select2 ' option:selected ').each(function(){
$("" ).appendTo("#" select1 "");
$(this).remove();
});
}
function moveAllToLeft(select1,select2)//Move all To the left
{
$('#' select2 ' option').each(function(){
$("

If you want to double-click an option in the select to transfer the current value to another select, you need to bind a select event as follows
Copy code The code is as follows:

$('#sel2').bind('dblclick',function(){//Bind double-click to the drop-down box Event
moveToRight('sel2','sel3');
});
$('#sel3').bind('dblclick',function(){
moveToLeft('sel2' ,'sel3');
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn