JQuery gets and sets Select options
Get Select:
Get select selected text:
$("#ddlRegType").find("option:selected").text();
Get select selected value :
$(“#ddlRegType “).val();
Get the selected index of select:
$(“#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<count;i++) { if($(“#ddlRegType “).get(0).options[i].text == text) { $(“#ddlRegType “).get(0).options[i].selected = true; break; } }
Clear Select:
$(“#ddlRegType “).empty();
For more JQuery settings to get the value of an option in the drop-down menu (more complete), please refer to related articles Follow PHP Chinese website!