Home > php教程 > PHP开发 > JQuery settings to get the value of an option in the drop-down menu (more comprehensive)

JQuery settings to get the value of an option in the drop-down menu (more comprehensive)

高洛峰
Release: 2016-12-15 16:09:08
Original
1597 people have browsed it

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;
Copy after login

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;
}
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template