Basic operations
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Document</title></Head><Body> <Script> //Create a Select functionCreateselect () {varMyselect=Document.createelement ("Select"); Myselect.id= 'Myselect'; Document.body.appendChild (Myselect); } createselect (); //Add Option functionaddoption () {varObjselect=Document.queryselector ("#mySelect"); Objselect.add (NewOption ("Text 1", "value 1"));//IEObjSelect.options.add (NewOption ("Text 2", "Value 2"));//the text is a display of content} addoption (); //Remove All option functionremovealloption () {varObjselect=Document.queryselector ("#mySelect"); ObjSelect.options.length= 0; } //removealloption (); //Delete the current option functionRemovenow () {varObjselect=Document.queryselector ("#mySelect"); varIndex=Objselect.selectedindex; ObjSelect.options.remove (index); } removenow (); //get the contents of the current option functionGetnow () {varObjselect=Document.queryselector ("#mySelect"); varIndex=Objselect.selectedindex; varNowval=Objselect.options[index].value;//Objselect.options[index].textConsole.log (nowval);//Value 2} getnow (); //Modify Current Option functionmodifyoption () {varObjselect=Document.queryselector ("#mySelect"); varIndex=Objselect.selectedindex; Objselect.options[index]=NewOption ("the newly modified","New"); } modifyoption (); //Delete Select functionRemoveselect () {varObjselect=Document.queryselector ("#mySelect"); ObjSelect.parentNode.removeChild (Objselect); } removeselect (); </Script></Body></HTML>
...
JS Operation Select