Summary of common methods for setting and obtaining Select
Jun 19, 2017 pm 04:16 PM1. Get the text selected by select:
$("#cusChildTypeId").find("option:selected").text();
$("#cusChildTypeId option:selected").text ()
2. Get the value selected by select:
$("#ddlRegType ").val();
3. Get the index selected by select :
$("#ddlRegType ").get(0).selectedIndex;
4. Get the number of selected items
$("#cusChildTypeId").get(0).options .length
5.Set the selected index of select:
$("#cusChildTypeId").get(0).selectedIndex=index;//index is the index value
6. Set the selected value of select:
$("#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<count;i++) { if($("#cusChildTypeId").get(0).options.text == text) { $("#cusChildTypeId").get(0).options.selected = true; break; } }
2>.
$("#cusChildTypeId").val(text); $("#cusChildTypeId").change();
8. Add an item to the select, 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<count;i++) { if($("#cusChildTypeId").get(0).options[i].value == value) { $("#cusChildTypeId").get(0).remove(i); break; } }
10. Clear Select:
1>. $("#cusChildTypeId").empty ();
2>. $("#cusChildTypeId").get(0).options.length = 0;
Example:
$("document").ready(function(){ $("#btn1").click(function(){ $("[name='checkbox']").attr("checked",'true');//全选 }) $("#btn2").click(function(){ $("[name='checkbox']").removeAttr("checked");//取消全选 }) $("#btn3").click(function(){ $("[name='checkbox']:even").attr("checked",'true');//选中所有奇数 }) $("#btn4").click(function(){ $("[name='checkbox']").each(function(){//反选 if($(this).attr("checked")){ $(this).removeAttr("checked"); } else{ $(this).attr("checked",'true'); } }) }) $("#btn5").click(function(){//输出选中的值 var str=""; $("[name='checkbox'][checked]").each(function(){ str+=$(this).val()+"\r\n"; //alert($(this).val()); }) alert(str); }) })
The above is the detailed content of Summary of common methods for setting and obtaining Select. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel.

How to set the scheduled time for publishing works on Douyin? How does it set the video duration?

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts)

Where is the Douyin tag set? How can it be tagged so that it can be pushed accurately?

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs)

How to set font size on mobile phone (easily adjust font size on mobile phone)

How to set the watermark in the middle on Weibo_How to set the watermark in the middle on Weibo
