Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 16:56:28
Original
1110 people have browsed it
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');
});
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template