<pre name="code">
Pull-down box tags in jsp:
<s:select name="sjx" id="sjx" list="sjxList" listKey="BM" listValue="MC" size="20" cssStyle="width:100%;height:70px; border:0" multiple="true"></s:select>
The code copy is as follows:
<pre name="code">
multiple="true" means to support multiple selection.
</pre><pre code_snippet_id="487056" snippet_file_name="blog_20141017_5_1612209" name="code">
How to flexibly create items under the select tag in js:
The code copy is as follows:
<pre name="code">var oSelect = $("sjx");<span style="white-space:pre"> </span>//sjx is the id of the select tag on the html or jsp page. If you use Extjs, you can use EXT.getDom('sjx') to get the tag
var oOption = document.createElement("OPTION");<span style="white-space:pre"> </span>// create OPTION subtag under the select tag in js
oSelect.options.add(oOption);<span style="white-space:pre"> </span>//Add the newly created OPTION sub-label to the select tag
oOption.value = "001";<span style="white-space:pre"> </span>//The value corresponding to the content
oOption.innerHTML ="Little Apple";<span style="white-space:pre"> </span>//The content of the drop-down box displayed
...and so on
Note: This method in js is more useful in specific occasions, such as: the request here does not return a specific interface, that is, it does not refresh the entire interface. Instead, use Ajax method to make some local data requests, then the following strut2 method will be invalid.
The code copy is as follows:
<pre name="code"><pre name="code">for(...){
HashMap<String,Object> map = new HashMap<String,Objcet>();
map.put("BM","001");
map.put("MC","Little Apple");
sjxList.add(map);
}
Another method is also very commonly used: use the feature of struts2 to define a List<Object> variable in Action (taking this example as an example, named: sjxList), and set the set and get methods.
Through a HashMap object, add content, such as:
</pre>When returning to the interface, "Little Apple" will be displayed in the select drop-down box of the interface.
<pre name="code">The easiest way: manually add the OPTION item of the select tag directly on the jsp page<html> <body> <form> <select id="cars" name="cars"> <option value="volvo">Volvo</option> <option value="binli">Binli</option> <option value="mazda" selected="selected">Mazda</option> <option value="audi">Audi</option> </select> </form> </body> </html>