Selection add option and place the last item
HTML code:
<form>
<select name= "Location" id= "Location" >
<option value= "Beijing1" >beijing</option>
<option value= "Shanghai1" >shanghai</option>
<option value= "CHENGDU1" >chengdu</option>
<option value= "CHANGSHA1" >changsha</option>
</select>
</form>
JS Code:
var select=document.forms[0].elements[' location ';
First method: Add a radio option
var newoption=document.createelement (' option ');
var newtext=document.createtextnode (' Guangzhou ');
Newoption.appendchild (NewText);
Newoption.setattribute (' value ', ' Guangzhou ');
Select.appendchild (newoption);
The second method: Also add the Radio option, is not a lot easier, haha but not compatible with IE8 and above version
var newsoption=new Option (' nanchang1 ', ' Nanchang ');
Select.appendchild (newsoption);
The third method: Add a radio box to see, the best solution, this is convenient and compatible
var nnewoption=new Option (' fengcheng1 ', ' Fengcheng ');
Select.add (nnewoption,undefined);
Removal options:
The first method: Select.remove (i);//index starting from 0
The second method: Select.options[i]=null;
Method Three: Select.removechild (Select.options[i])
Single box add options and remove options in form