Collection
1. Determine if the value= "Paravalue" item exists in the SELECT option
2. Add an item to the Select option
3. Remove an item from the Select option
4. Delete selected items in select
5, modify the Select option Value= "Paravalue" text is "Paratext"
6. Set the first item of text= "Paratext" in Select to be selected
7. Set the "Paravalue" item in Select to Value=
8. Gets the value of the current selected item of select
9. Gets the text of the current selected item of select
10. Gets the index of the current selected item of select
11. Clear the Select item
- JS Code
- 1. Determine if the value= "Paravalue" item exists in the SELECT option
- function Jsselectisexititem (Objselect, Objitemvalue) {
- var isexit = false;
- For (var i = 0; i < objSelect.options.length; i++) {
- if (Objselect.options[i].value = = Objitemvalue) {
- Isexit = true;
- Break ;
- }
- }
- return isexit;
- }
- 2. Add an item to the Select option
- function Jsadditemtoselect (Objselect, Objitemtext, Objitemvalue) {
- //Determine if there is
- if (Jsselectisexititem (Objselect, Objitemvalue)) {
- Alert ("The value of the item already exists");
- } Else {
- var varitem = New Option (Objitemtext, Objitemvalue);
- ObjSelect.options.add (Varitem);
- Alert ("join successfully");
- }
- }
- 3. Remove an item from the Select option
- function Jsremoveitemfromselect (Objselect, Objitemvalue) {
- //Determine if there is
- if (Jsselectisexititem (Objselect, Objitemvalue)) {
- For (var i = 0; i < objSelect.options.length; i++) {
- if (Objselect.options[i].value = = Objitemvalue) {
- ObjSelect.options.remove (i);
- Break ;
- }
- }
- Alert ("delete successfully");
- } Else {
- Alert ("The item does not exist in this select");
- }
- }
- 4. Delete the selected item in select
- function Jsremoveselecteditemfromselect (objselect) {
- var length = objselect.options.length-1;
- For (var i = length; I >= 0; i--) {
- if (objselect[i].selected = = true) {
- Objselect.options[i] = null;
- }
- }
- }
- 5. Modify the text of value= "Paravalue" in the Select option to "Paratext"
- function Jsupdateitemtoselect (Objselect, Objitemtext, Objitemvalue) {
- //Determine if there is
- if (Jsselectisexititem (Objselect, Objitemvalue)) {
- For (var i = 0; i < objSelect.options.length; i++) {
- if (Objselect.options[i].value = = Objitemvalue) {
- Objselect.options[i].text = Objitemtext;
- Break ;
- }
- }
- Alert ("successful modification");
- } Else {
- Alert ("The item does not exist in this select");
- }
- }
- 6. Set the first item of text= "Paratext" in Select to be selected
- function Jsselectitembyvalue (Objselect, Objitemtext) {
- //Determine if there is
- var isexit = false;
- For (var i = 0; i < objSelect.options.length; i++) {
- if (Objselect.options[i].text = = Objitemtext) {
- objselect.options[i].selected = true;
- Isexit = true;
- Break ;
- }
- }
- //show The results
- if (isexit) {
- Alert ("selected successfully");
- } Else {
- Alert ("The item does not exist in this select");
- }
- }
- 7. Set the item of value= "Paravalue" in Select to select
- Document.all.objSelect.value = Objitemvalue;
- 8. Gets the value of the current selected item of select
- var currselectvalue = Document.all.objSelect.value;
- 9. Gets the text of the current selected item of select
- var currselecttext = Document.all.objselect.options[document.all.objselect.selectedindex].text;
- 10. Get the index of the current selected item of select
- var currselectindex = Document.all.objSelect.selectedIndex;
- 11. Clear the Select item
- document.all.objSelect.options.length = 0;
Turn JavaScript Operations Select Control Daquan (add, modify, delete, select, empty, Judge existence, etc.)