Form, select and transfer the navigation menu

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.