JavaScript Learning Notes drop-down selection box action

Source: Internet
Author: User

For the dropdown box is a very large operation, these days the project needs to summarize

First, dynamic construction option

Sometimes we need to dynamically build the values in the dropdown box, where we'll use var varitem = new Option ("text", "value"), build one or more <option value= "value" > Text </option>

var varitem = new Option ("Studentname", "name");

Example 1: When the form is loaded, an option is automatically constructed


Of course, I think it should be possible to build multiple options at once, may be declaring an array or a JSON object to add, but specifically how to add more than one option at a glance, will friends look pointing

Example 2: The use of JS to delete a column for the Stunumber drop-down selection box, later if made dynamic, you can use the call method to delete the specified column of information.


Example 3: Delete the value of the selected drop-down box, can be implemented by an event method, we can randomly select a column, and then click the button, then the column will be deleted

Example 4: Empty the value in the drop-down selection box


Example 5: To get the value of option inside name, we pass a button event, click, Pop Up the dialog box, the information inside is the value of name


Example 6: Output the subscript value of option, starting from 0


Second, the echo of select (combined with JSP)

Usually when we do update user information, we need to echo the drop-down selection box information, this time if you use JSP development, you can use the JSTL tag <c:if>

First introduce the JSTL tag library: <%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>

<select id= "Sort" value= "${sort}" ><option name= "name" <c:if test= "${' name ' eq sort}" >selected</c:if >>studentname</option><option name= "Stunum" <c:if test= "${' stunum ' eq sort}" >selected</c:if >>studentnumber</option></select>

Continuous summary in ~ ~ ~

Reference blog:

Http://www.cnblogs.com/Herist/archive/2007/09/24/903890.htmlhttp://www.jb51.net/article/44657.htm
(Reproduced this site article please indicate the author and sourceCoderthe extraordinary, do not use for any commercial use)



JavaScript Learning Notes drop-down selection box action

Related Article

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.