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

A brief analysis of the common methods of getting and setting Select options in JQuery_jquery

WBOY
Release: 2016-05-16 17:30:27
Original
1270 people have browsed it

1. Get the selected text:
$("#cusChildTypeId").find("option:selected").text();
$("#cusChildTypeId option :selected").text()

2. Get the selected value:
$("#ddlRegType ").val();

3. Get the selected index:
$("#ddlRegType ").get(0).selectedIndex;

4. Get the number of select items

$("#cusChildTypeId").get(0).options.length

5. Set select selected index:
$("#cusChildTypeId") .get(0).selectedIndex=index;//index is the index value

6. Set the selected value:
$("#cusChildTypeId").attr(" value","Normal");
$("#cusChildTypeId").val("Normal");
$("#cusChildTypeId").get(0).value = "Normal";

7. Set select selected text:
1>.var count=$("#cusChildTypeId").get(0).options.length;
for(var i=0;i                                                                            cusChildTypeId").get(0).options.selected = true;
              break;
2>.$("#cusChildTypeId").val(text);
$("#cusChildTypeId").change();


8. Add a Item, the display content is text, the value is value

$("#cusChildTypeId").get(0).options.add(new Option(text,value));

9. Delete items with value in select
var count = $("#cusChildTypeId").size();
for(var i=0;i                                                                                                                      remove(i); break;
}
}


10. Clear Select:

1>. .empty ();
2>. $("#cusChildTypeId").get(0).options.length = 0;

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