JS to create an HTML tag, add the default option under Select Value and text

Source: Internet
Author: User

<pre name= "code" class= "Java" >
drop-down box tags in jsp:
<s:select name= "SJX" id= "SJX" list= "sjxlist" listkey= "BM" listvalue= "MC" size= "cssstyle=" width:100%;height : 70px; border:0 "multiple=" true "></s:select>
<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 >js How to flexibly create items under the Select tab:
<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 var ooption = document.createelement ("OPTION") with Ext.getdom (' SJX '); <span style= "white-space:pre" ></span>//js create option sub-label under Select Tab OSelect.options.add (ooption);< Span style= "White-space:pre" ></span>//Add the new option sub-label to the Select tab ooption.value = "001"; <span style= " White-space:pre "></span>//content corresponds to value ooption.innerhtml =" Small Apple "; <span style=" White-space:pre "></ span>//Displays the contents of the drop-down box ... And so on
Note:js in this way, in a specific situation is more useful, such as: Here the request does not return a specific interface, that is, do not refresh the entire interface. Instead of using an AJAX asynchronous request to make some partial data requests, the following strut2 will not work.


<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, which is also very common: Use the STRUTS2 feature to define a list<object> variable in action (in this case, named: sjxlist), and set the set, get method.
With a HashMap object, add content, such as:
</pre> when returned to the interface, the "Little Apple" is displayed in the Select drop-down box in the interface.
<pre name= "code" class= "HTML" > The simplest way: Manually add option items to the Select tab directly on the JSP page 




JS to create an HTML tag, add the default option under Select Value and text

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.