Home > Article > Web Front-end > A brief analysis of the common methods of getting and setting Select options in JQuery_jquery
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
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
}
}
10. Clear Select:
1>. .empty ();
2>. $("#cusChildTypeId").get(0).options.length = 0;