JS Code 1. Determine if there is a value= "Paravalue" Item 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 function to the Select option Jsadditemtoselect (Objselect, Objitemtext, objitemvalue) { //Determine if there is a if (Jsselectisexititem (Objselect, Objitemvalue)) { alert ("The value of the item already exists"); } else { var varitem = new Option (Objitemtext, obj Itemvalue); ObjSelect.options.add (varitem); alert ("Join successfully"); } } //3. Remove one item function Jsremoveitemfromselect (Objselect, Objitemvalue) from the Select option { // To determine if there is a if (Jsselectisexititem (Objselect, Objitemvalue)) { for (var i = 0; I < objSelect.options.length i++) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&N bsp; if (Objselect.options[i].value = = objitemvalue) { ObjSelect.options.remove (i); break; } } Alert ("Successful deletion"); } else { alert ("This item does not exist in this select"); } } 4. Delete selected items 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 Select option Value= "Paravalue" text is "Paratext" function Jsupdateitemtoselect (Objselect, Objitemtext, Objitemvalue) { To determine whether 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 the select"); } } 6. Set the first item of text= "Paratext" in Select to select function Jsselectitembyvalue (Objselect, Objitemtext) { To determine whether 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 ("Successfully selected"); } else { Alert ("The item does not exist in the select"); } } 7. Set the item of value= "Paravalue" in Select to select Document.all.objSelect.value = Objitemvalue; 8. Get the Value,index,text of the current selected item function GetValue (obj) { return obj.value; } 9. Get the index of the currently selected item function GetIndex (obj) { return obj.selectedindex; } 10. Get the text of the currently selected item function GetText (obj) { return obj.options[obj.selectedindex].text; } 11. Clear all options function Clear (obj) { obj.options.length = 0; } |