Home >Web Front-end >JS Tutorial >JQuery code to get and set Select options_jquery

JQuery code to get and set Select options_jquery

WBOY
WBOYOriginal
2016-05-16 18:35:26825browse
Get Select:
Get selected text:
$("#ddlRegType").find("option:selected").text();
Get selected value :
$("#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{ if($("#ddlRegType ").get(0).options[i].text == text)
{
$("#ddlRegType ").get(0). options[i].selected = true;
break;
}
}
Clear Select:
$("#ddlRegType ").empty();
Statement:
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