jQuery gets the Select Select Text and Value:
$("#select_id").change(function(){//code...}); //Add an event for Select, triggering when one of them is selected
var checkText=$("#select_id").find("option:selected").text(); //Get the Select selected Text
var checkValue=$("#select_id").val(); //Get the Value selected by Select
var checkIndex=$("#select_id ").get(0).selectedIndex; //Get the index value selected by Select
var maxIndex=$("#select_id option:last").attr("index"); //Get the maximum index value of Select
jQuery adds/deletes Select's Option item:
$("#select_id").append("<option value='Value'>Text</option>"); //Add an Option (drop-down item) to Select
$("#select_id").prepend("<option value='0'>Please select </option>"); //Insert an Option for Select (first position)
$("#select_id option:last").remove(); //Delete the maximum index value Option in Select (last)
$("#select_id option[index='0']").remove(); //Delete the Option with the index value of 0 in Select (first)
$("#select_id option[value='3']").remove(); //Delete the Option of Value='3' in Select
$("#select_id option[text='4']").remove(); //Delete the Option of Text='4' in Select
Content clear:
$("#charCity").empty();
Copy the codeThe code is as follows:
$("#select_id").change(function(){//code...}); //Add an event for Select, triggering when one of them is selected
var checkText=$("#select_id").find("option:selected").text(); //Get the Select selected Text
var checkValue=$("#select_id").val(); //Get the Value selected by Select
var checkIndex=$("#select_id ").get(0).selectedIndex; //Get the index value selected by Select
var maxIndex=$("#select_id option:last").attr("index"); //Get the maximum index value of Select
jQuery adds/deletes Select's Option item:
Copy the codeThe code is as follows:
$("#select_id").append("<option value='Value'>Text</option>"); //Add an Option (drop-down item) to Select
$("#select_id").prepend("<option value='0'>Please select </option>"); //Insert an Option for Select (first position)
$("#select_id option:last").remove(); //Delete the maximum index value Option in Select (last)
$("#select_id option[index='0']").remove(); //Delete the Option with the index value of 0 in Select (first)
$("#select_id option[value='3']").remove(); //Delete the Option of Value='3' in Select
$("#select_id option[text='4']").remove(); //Delete the Option of Text='4' in Select
Content clear:
Copy the codeThe code is as follows:
$("#charCity").empty();