-Please select-, which is actually the same as in html There is no difference, but JSP can use el expressions to achieve more convenient functions."/> -Please select-, which is actually the same as in html There is no difference, but JSP can use el expressions to achieve more convenient functions.">
In the process of WEB development, we often encounter functional requirements for information modification. At this time, we provide the user with a JSP page that displays the current information and allows the user to reset the new value.
In this page, a drop-down list is generally indispensable. As for its processing method, I have thought of one before, and the idea is as follows: set a hidden field on the page to save the value passed from the background; then output the drop-down list on the page, and its value is the default at this time, that is, the first One item; get the value in the hidden field in the js code snippet and determine whether it is equal to the id value of the drop-down item in the loop. If equal, set the selected status of the item. Because this method is too cumbersome.
The following are two commonly used processing methods.
Method one:
<select id="user_id" name="user_id"> <c:forEach items="${users}" var="u"> <option value="${u.id }" <c:if test="${user.user_id==u.id}"><c:out value="selected"/></c:if>> ${u.name} </option> </c:forEach> </select>
Method two:
<select id="projectPorperty" name="projectPorperty"> <option value="1">实施</option> <option value="0">研发</option> </select> <script> form.projectPorperty.value = '${user.projectPorperty}'; </script>
The above two methods have their own advantages and disadvantages. Choose as appropriate according to the situation!
The above is the detailed content of drop down list in jsp page. For more information, please follow other related articles on the PHP Chinese website!