$("#select_id option:last").remove(); //Delete the Option with the largest index value in Select (the last one)
$("#select_id option[index='0']").remove(); //Delete the Option (first) with index value 0 in Select
$("#select_id option[value='3']").remove(); //Delete the Option with Value='3' in Select
$("#select_id option[text='4']").remove(); //Delete the Option with Text='4' in Select
$("#select_id").empty(); //Empty
$("#select_id ").get(0).selectedIndex=1; //Set the item with Select index value 1 to select
$("#select_id ").val(4); //Set the Select value to 4 to select the item
$("#select_id option[text='jQuery']").attr("selected", true); //Set the Text value of Select to the jQuery item selected
$("#select_id").val(); //Get the value of the selected item
$("#select_id ").get(0).selectedIndex; //Get the index value of the selected item
$("#select_id").find("option:selected").text(); //Get the text of the selected item
$("#select_id option:last").attr("index"); //Get the maximum index value of Select
A code sample is attached. The code function is to change the number of days in the option "Day" according to the actual selected "Year" and "Month".
Written in php, the default $("select.day") initially has 31 days, because the default is January:
$(document).ready(function() {
$("select.month, select.year").change(function() { //Changes in "year" and "month" may cause changes in "day"
$("select.day").empty(); //Very important, clear it first
for (var i = 1; i < 31; i ) {
var option = $(""); //Append an option if the number of days is 31 days
}
If (month === 2) {
$("select.day option:last").remove();
$("select.day option:last").remove(); //The number of days in February is 28
var year = $("select.year").val();
If ((year % 4 === 0 && year % 100) || year % 400 === 0)
$("select.day").append(""); //Add one to the number of days in February in leap years
}
});
});
The above is a summary of jQuery’s implementation of adding, deleting, modifying, and checking select operations. I hope you all like it.
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