Home Web Front-end JS Tutorial js method to add the value and text of the default option under select_javascript skills

js method to add the value and text of the default option under select_javascript skills

May 16, 2016 pm 04:33 PM
option select

</p>
<p>Drop-down box tag in jsp: </p>
<p><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></p>
<p></p>
<div class="codetitle">
<span><a style="CURSOR: pointer" data="14907" class="copybut" id="copybut14907" onclick="doCopy('code14907')"><u>Copy code</u></a></span> The code is as follows:</div>
<div class="codebody" id="code14907">
<br>
<pre name="code" class="html"> <br>
<br>
multiple="true" means supporting multiple selections. <br>
<br>
<br>
</div>
<br>
A flexible way to create items under the select tag in js: 
<p></p>
<div class="codetitle">
<span><a style="CURSOR: pointer" data="6621" class="copybut" id="copybut6621" onclick="doCopy('code6621')"><u>Copy code</u></a></span> The code is as follows:</div>
<div class="codebody" id="code6621">
<br>
<pre name="code" class="javascript">var oSelect = $("sjx");<span style="white-space:pre"> </span>//sjx is html or The id of the select tag on the jsp page. If you use Extjs, you can use EXT.getDom('sjx') to get the tag <br>
<br>
var oOption = document.createElement("OPTION");<span style="white-space:pre"> </span>//Create the OPTION sub-tag under the select tag in js <br>
oSelect.options.add(oOption);<span style="white-space:pre"> </span>//Add the new OPTION sub-tag to the select tag <br>
oOption.value = "001";<span style="white-space:pre"> </span>//The value corresponding to the content <br>
oOption.innerHTML ="Little Apple";<span style="white-space:pre"> </span>//Contents of the displayed drop-down box <br>
...and so on<br>
</div>
<p>Note: This method in js is more useful in specific situations. For example, the request here does not return a specific interface, that is, the entire interface is not refreshed. Instead, Ajax asynchronous requests are used to make some local data requests. At this time, the strut2 method below will be invalid. </p>
<p></p>
<div class="codetitle">
<span><a style="CURSOR: pointer" data="84595" class="copybut" id="copybut84595" onclick="doCopy('code84595')"><u>Copy code</u></a></span> The code is as follows:</div>
<div class="codebody" id="code84595">
<br>
<pre name="code" class="java"><pre name="code" class="java">for(...){ <br>
HashMap<String,Object> map = new HashMap<String,Objcet>(); <br>
map.put("BM","001"); <br>
map.put("MC","Little Apple"); <br>
sjxList.add(map); <br>
} <br>
</div>
<p>Another way is also very common: use the features of struts2 to define a List<Object> variable in Action (take this example as an example, named: sjxList), and set the set and get methods. </p>
<p>Add content through a HashMap object, such as: </p>
<p>
When returning to the interface, "Little Apple" will be displayed in the select drop-down box of the interface.

<pre name="code" class="html">最简单的一种方式: 
直接在jsp页面手动添加select标签的OPTION项 
<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> 
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Asynchronous processing method of Select Channels Go concurrent programming using golang Asynchronous processing method of Select Channels Go concurrent programming using golang Sep 28, 2023 pm 05:27 PM

Asynchronous processing method of SelectChannelsGo concurrent programming using golang Introduction: Concurrent programming is an important area in modern software development, which can effectively improve the performance and responsiveness of applications. In the Go language, concurrent programming can be implemented simply and efficiently using Channels and Select statements. This article will introduce how to use golang for asynchronous processing methods of SelectChannelsGo concurrent programming, and provide specific

How to hide the select element in jquery How to hide the select element in jquery Aug 15, 2023 pm 01:56 PM

How to hide the select element in jquery: 1. hide() method, introduce the jQuery library into the HTML page, you can use different selectors to hide the select element, the ID selector replaces the selectId with the ID of the select element you actually use; 2. css() method, use the ID selector to select the select element that needs to be hidden, use the css() method to set the display attribute to none, and replace selectId with the ID of the select element.

What does option mean in linux documentation? What does option mean in linux documentation? Mar 07, 2023 am 10:41 AM

In Linux, option refers to a command option, which is a switch that adjusts the command execution behavior. That is, different options determine the display results of the command. Options are divided into long options and short options: 1. Short options are guided by "-". When there are multiple short options, spaces are used to separate each option; 2. Long options are complete words. , and usually cannot be combined.

How to implement change event binding of select elements in jQuery How to implement change event binding of select elements in jQuery Feb 23, 2024 pm 01:12 PM

jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

What is the reason why Linux uses select? What is the reason why Linux uses select? May 19, 2023 pm 03:07 PM

Because select allows developers to wait for multiple file buffers at the same time, it can reduce IO waiting time and improve the IO efficiency of the process. The select() function is an IO multiplexing function that allows the program to monitor multiple file descriptors and wait for one or more of the monitored file descriptors to become "ready"; the so-called "ready" state is Refers to: the file descriptor is no longer blocked and can be used for certain types of IO operations, including readable, writable, and exceptions. select is a computer function located in the header file #include. This function is used to monitor file descriptor changes—reading, writing, or exceptions. 1. Introduction to the select function. The select function is an IO multiplexing function.

How to use the select syntax of mysql How to use the select syntax of mysql Jun 01, 2023 pm 07:37 PM

1. Keywords in SQL statements are not case-sensitive. SELECT is equivalent to SELECT, and FROM is equivalent to from. 2. To select all columns from the users table, you can use the symbol * to replace the column name. Syntax--this is a comment--query out [all] data from the [table] specified by FEOM. * means [all columns] SELECT*FROM--query out the specified data from the specified [table] from FROM Data of column name (field) SELECT column name FROM table name instance--Note: Use English commas to separate multiple columns selectusername, passwordfrom

Implement Select Channels Go concurrent programming performance optimization through golang Implement Select Channels Go concurrent programming performance optimization through golang Sep 27, 2023 pm 01:09 PM

Implementing SelectChannels through golang Performance optimization of Go concurrent programming In the Go language, it is very common to use goroutine and channel to implement concurrent programming. When dealing with multiple channels, we usually use select statements for multiplexing. However, in the case of large-scale concurrency, using select statements may cause performance degradation. In this article, we will introduce some implementations of select through golang

Select Channels Go concurrent programming for reliability and robustness using golang Select Channels Go concurrent programming for reliability and robustness using golang Sep 28, 2023 pm 05:37 PM

SelectChannels for Reliability and Robustness Using Golang Introduction to Concurrent Programming: In modern software development, concurrency has become a very important topic. Using concurrent programming can make programs more responsive, utilize computing resources more efficiently, and be better able to handle large-scale parallel computing tasks. Golang is a very powerful concurrent programming language. It provides a simple and effective way to implement concurrent programming through go coroutines and channel mechanisms.

See all articles