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

jQuery select operation implementation code_jquery

WBOY
Release: 2016-05-16 18:53:21
Original
1077 people have browsed it
//Events when changing
Copy code The code is as follows:

$("#testSelect").change(function(){ //Event occurred
jQuery('option:selected', this).each(function(){ //Print out multiple selected values
alert(this.value);
});
});

//Print the selected item
Copy code The code is as follows:

Method 1: $("select#Clubs").children("[@selected]" ).each(function(){
alert(this.text);
});
Method 2: $("#selBags").val(); //This is faster, but Single selection only


//Get the selection value of the drop-down menu
Copy code The code is as follows:

$(#testSelect option:selected').text();
or $("#testSelect").find('option:selected ' ).text();

//Remove
removeOption(index/value/regex[, selectedOnly])
Copy code The code is as follows:

$('select#Clubs option:selected').remove();

//Make an option selected
Copy the code The code is as follows:

var select = $(tdsEdit[0]).find("select"); //Get select
$(select).children().each(function(){
if ( $(this).text()=="option you want")

//jQuery method
Copy code The code is as follows:

$(this).attr("selected","true"); //Or selected
//javascript method
this.selected = true;
});

Reference
http://www.texotela.co .uk/code/jquery/select/
http://blog.jeremymartin.name/2008/02/easy-multi-select-transfer-with-jquery. html
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