Home >Web Front-end >JS Tutorial >jQuery operation memo record for Select_jquery

jQuery operation memo record for Select_jquery

WBOY
WBOYOriginal
2016-05-16 18:05:18894browse
jQuery gets the Text and Value selected by Select:

Syntax explanation:
1. $("#select_id").change(function(){//code...} ); //Add an event for Select, triggered when one of the items is selected
2. var checkText=$("#select_id").find("option:selected").text(); //Get the Select selection Text
3. var checkValue=$("#select_id").val(); //Get the Value selected by Select
4. var checkIndex=$("#select_id ").get(0). selectedIndex; //Get the index value selected by Select
5. var maxIndex=$("#select_id option:last").attr("index"); //Get the maximum index value of Select

jQuery sets the Text and Value selected by Select:

Syntax explanation:
1. $("#select_id ").get(0).selectedIndex=1; //Set Select The item with index value 1 is selected
2. $("#select_id ").val(4); //Set the Select Value to 4 and the item is selected
3. $("#select_id option[text ='jQuery']").attr("selected", true); //Set the Text value of Select to the jQuery item selected

jQuery adds/removes the Option item of Select:

Syntax explanation:
1. $("#select_id").append(""); //Append an Option (drop-down item) to Select
2 . $("#select_id").prepend(""); //Insert an Option (first position) for Select
3. $("#select_id option:last" ).remove(); //Delete the Option with the largest index value in Select (the last one)
4. $("#select_id option[index='0']").remove(); //Delete the index in Select Option with value 0 (first)
5. $("#select_id option[value='3']").remove(); //Remove Option with Value='3' in Select
6. $("#select_id option[text='4']").remove(); //Delete the Option with Text='4' in Select
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