Home > Article > Web Front-end > jQuery gets and sets the value of the select drop-down box implementation code_jquery
Get Select:
Get selected text:
$("#ddlRegType").find("option:selected").text();
Get the value selected by select:
$("#ddlRegType ").val();
Get the selected index:
$("#ddlRegType ").get(0).selectedIndex;
Set select:
Set select selected index:
$("#ddlRegType ").get(0).selectedIndex=index;//index is the index value
Set select selected value:
$("#ddlRegType ").attr("value","Normal");
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;
Set select selected text:
var count=$("#ddlRegType option").length;
for(var i=0;i
{
$("#select_id option[text='jQuery']").attr("selected", true);
Set the select option:
$("#select_id").append(""); //Add an option
$("#select_id").prepend(""); //Insert an option in front
$("#select_id option[index='0']").remove();//Delete the Option
with index value 0
$("#select_id option[value='3']").remove(); //Delete Optionwith value 3
$("#select_id option[text='4']").remove(); //Delete the Option with TEXT value 4
Clear Select:
$("#ddlRegType ").empty();