This article mainly introduces how to create html tags in js and add the default option value and text under select. It is very practical and can be viewed by friends.
The drop-down box label in jsp:
The Code is as follows:
Multiple = "true" means multiple options are supported.
How to flexibly create items under the select label in js: The Code is as follows:
Var oSelect = $ ("sjx"); // sjx is the id of the select tag on the html or jsp page. If Extjs is used, EXT. getDom ('sjx') to obtain tags
Var oOption = document. createElement ("OPTION"); // create the OPTION sub-tag under the select tag in js
OSelect. options. add (oOption); // add the newly created OPTION sub-tag to the select tag.
OOption. value = "001"; // value corresponding to the content
OOption. innerHTML = "apple"; // the content of the displayed drop-down box
... And so on
Note: This method in js is useful in specific scenarios. For example, the request does not return a specific interface, that is, the whole interface is not refreshed. Instead, asynchronous requests using Ajax are used to make some local data requests. In this case, the following strut2 method will be invalid.
The Code is as follows:
For (...){
HashMap
Map = new HashMap
();
Map. put ("BM", "001 ");
Map. put ("MC", "apple ");
SjxList. add (map );
}
Another method is also very commonly used: using the features of struts2, define a List in ActionVariable (in this example, name it sjxList) and set the set and get methods.
Add content through a HashMap object, for example:
When the interface is returned, the "apple" is displayed in the select drop-down box ".
The simplest method is to manually add the OPTION item of the select label on the jsp page.