Home  >  Article  >  Web Front-end  >  jQuery select operation implementation code_jquery

jQuery select operation implementation code_jquery

WBOY
WBOYOriginal
2016-05-16 18:53:211078browse
//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
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