Home > Web Front-end > JS Tutorial > body text

jquery code to get drop-down box value_jquery

WBOY
Release: 2016-05-16 18:03:26
Original
815 people have browsed it

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 the selected index of select:
$("#ddlRegType ").get(0).selectedIndex=index;//index is the index value

Set the selected value of select:

Copy code The code is as follows:

$("#ddlRegType ").attr("value" ,"Normal");
$("#ddlRegType ").val("Normal");
$("#ddlRegType ").get(0).value = value;

Set select selected text:
Copy code The code is as follows:

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;
}
}

$("#select_id option[text='jQuery']").attr("selected", true);


Set the select option item:
Copy code The code is as follows:

$("#select_id").append(""); //Add an option
$("#select_id").prepend(" "); //Insert an option in front
$("#select_id option:last").remove(); //Remove the Option with the largest index value
$("#select_id option[index=' 0']").remove(); //Delete the Option with an index value of 0
$("#select_id option[value='3']").remove(); //Delete the Option with a value of 3
$("#select_id option[text='4']").remove(); //Delete Option with TEXT value 4


Clear Select:
$("#ddlRegType ").empty();
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!