1. code example
<! DOCTYPE html>"Utf-8">"Post"action="select.html"> <SelectId="NewLocation"> <option selected>SelectA topic</option> <option value="script01.html">javascript</option> <option value="script02.html">jquery</option> <option value="script03.html">jquery mobile</option> <option value="script04.html">html5</option> <option value="script05.html">css3</option> </Select> </form></body>"Text/javascript">window.onload=Init; Window.unload=function () {}; function init () {document.getElementById ("NewLocation"). SelectedIndex =0; Console.log (document.getElementById ("NewLocation"). options); document.getElementById ("NewLocation"). onchange =Jumppage; } function Jumppage () {varNewloc = document.getElementById ("NewLocation"); varNewPage =Newloc.options[newloc.selectedindex].value; if(NewPage! ="") {window.location=NewPage; } }</script>
2. Key Analysis:
2.1. Window.onunload = function () {}:
The OnUnload event occurs when the user exits the page;
2.2, SelectedIndex:
The SelectedIndex property sets or returns the index number of the selected option in the drop-down list.
Note: If multiple selections are allowed, only the index number of the first selected option is returned.
2.3. Options:
Delete a selected item
Objselect.options[objselect.selectedindex] = null;
Add Item
Objselect.options[objselect.length] = new Option ("Hello", "Hello");
Modify the items in the selection
Objselect.options[objselect.selectedindex] = new Option ("Hello", "Hello");
Get the text of the selected item
Objselect.options[objselect.selectedindex].text;
Get the value of the selected item
Objselect.options[objselect.selectedindex].value;
Form, select and transfer the navigation menu