Home >Web Front-end >JS Tutorial >JQuery settings to get the value of an option in the drop-down menu (more complete)_jquery
JQuery gets and sets Select options
Get Select:
Get the text selected by select:
$(“#ddlRegType”).find(“option:selected”).text();
Get the value selected by select:
$(“#ddlRegType “).val();
Get the index selected by 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();