Home > Web Front-end > JS Tutorial > jQuery gets and sets the value of the select drop-down box implementation code_jquery

jQuery gets and sets the value of the select drop-down box implementation code_jquery

WBOY
Release: 2016-05-16 17:16:56
Original
1120 people have browsed it

Get Select:

Get selected text:

$("#ddlRegType").find("option:selected").text();


Get the value selected by select:

$("#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)
{
                                                                                                           
$("#select_id option[text='jQuery']").attr("selected", true);


Set the select option:


$("#select_id").append(""); //Add an option $("#select_id").prepend(""); //Insert an option in front

$("#select_id option:last").remove(); //Delete the Option with the largest index value

$("#select_id option[index='0']").remove();//Delete the Option

with index value 0

$("#select_id option[value='3']").remove(); //Delete Option

with value 3

$("#select_id option[text='4']").remove(); //Delete the 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