Selection add option and put it in 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 way: is also to add a single option, is not much simpler, haha but incompatible IE8 and the above version
var newsoption=new Option (' nanchang1 ', ' Nanchang ');
Select.appendchild (newsoption);
The Third Way: Add a single check 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;
The third method: Select.removechild (Select.options[i])
Here are three ways to uncheck the radio of a single marquee
This article relies on jquery, the first of which is implemented using jquery, and the third Way is based on JS and Dom.
The above is a small part of the form to introduce the form of the optional box to add options and remove options, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!