JS Add Select the default option value and Text method _javascript tips

Source: Internet
Author: User

<pre name= "code" class= "Java" >

Drop-down box label in JSP:

<s:select name= "SJX" id= "SJX" list= "sjxlist" "BM" listkey= "MC" listvalue= "size=" cssstyle= : 70px; border:0 "multiple=" true ></s:select>

Copy Code code as follows:

<pre name= "code" class= "HTML" >

Multiple= "true" means that multiple selections are supported.
</pre><pre code_snippet_id= "487056" snippet_file_name= "blog_20141017_5_1612209" "Name=" code "class=" JavaScript ">

In JS, the way to create items under the Select tab is flexible:

Copy Code code as follows:

<pre name= "Code" class= "javascript" >var Oselect = $ ("SJX"); <span style= "White-space:pre" > </span>// SJX is the ID of the SELECT tag on the HTML or JSP page, and if you use ExtJS, you can get the label with Ext.getdom (' SJX ')

var ooption = document.createelement ("option"); <span style= "White-space:pre" > </span>// The option sub tag in JS to create the Select label
OSelect.options.add (ooption); <span style= "White-space:pre" > </span>//Add the new Option Child label to the Select label
Ooption.value = "001"; <span style= "White-space:pre" > </span>//content corresponding value value
ooption.innerhtml = "Small Apple"; <span style= the contents of the Drop-down box displayed by the "White-space:pre" > </span>//
... Analogy

This approach in NOTE:JS is useful in specific situations, such as: This request does not return a specific interface, that is, not refreshing the entire interface. Instead of using an AJAX-style asynchronous request to do some local data requests, then the following Strut2 method will be ineffective.

Copy Code code as follows:

<pre name= "code" class= "java" ><pre name= "code" class= "java" >for (...) {
hashmap<string,object> map = new hashmap<string,objcet> ();
Map.put ("BM", "001");
Map.put ("MC", "small apple");
Sjxlist.add (map);

Another way is also very common: using the Struts2 feature, define a list<object> variable in the action (in this case, named: sjxlist) and set the set, get method.

Add content through a HashMap object, such as:

When the </pre> returns to the interface, the "Little Apple" is displayed in the Select Drop-down box of the interface.

 <pre name= "code" class= "HTML" > one of the easiest ways to manually add a select label to a JSP page  

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.