<!DOCTYPE HTML><HTML><Head><title>Test</title><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"/></Head><Body><Script>functionCreateselect (s_id) {varMyselect=Document.createelement ("Select"); Myselect.id=s_id; Document.body.appendChild (Myselect);}functionaddoption (X_text, Y_value, s_id) {varobj=document.getElementById (s_id); Obj.add (NewOption (X_text, Y_value));}//Clear Select optionfunctionRemoveAll (s_id) {varobj=document.getElementById (s_id); Obj.options.length= 0;}//clears the specified optionfunctionRemoveone (s_id, index) {varobj=document.getElementById (s_id); Obj.options.remove (index);}//Clear the selected optionfunctionRemoveselectone (s_id) {varobj=document.getElementById (s_id); varS_index=Obj.selectindex; Obj.options.remove (S_index);}//Gets the value of option options text valuefunctionGetValue (s_id) {varobj=document.getElementById (s_id); varS_index=Obj.selectedindex; varS_value=Obj.options[s_index].value; varS_text=Obj.options[s_index].text; alert (s_value); alert (s_text);}functionedit (s_id, index, X_text, y_value) {varobj=document.getElementById (s_id); Obj.options[index]= NewOption ("X_text", "Y_value");}functionRemoveselect (s_id) {varMyselect=document.getElementById (s_id); MySelect.parentNode.removeChild (myselect);} Createselect ("Myselect"); AddOption ("Text 1", "value 1", "Myselect"); AddOption ("Text 2", "Value 2", "Myselect"); AddOption ("Text 3", "Value 3", "Myselect"); Createselect ("MySelect2"); AddOption ("Text 1", "value 1", "MySelect2"); AddOption ("Text 2", "Value 2", "MySelect2"); AddOption ("Text 3", "Value 3", "MySelect2");//RemoveAll ("MySelect2");//Removeone ("MySelect2", 2);//Removeselectone ("Myselect");//getValue ("Myselect");//edit ("Myselect", 2);//removeselect ("MySelect2")</Script></Body></HTML>
Select Create, modify, value, delete JavaScript code