How to write a drop-down box in a jsp page: first set a hidden field in the page to save the value passed from the background; then output the drop-down list in the page; finally get the hidden field in the js code snippet The value in and determine whether it is equal to the id value of the drop-down item in the loop.
#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.
Recommended course: Java Tutorial.
As for its processing method, I have thought of one before. 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 then its value It is the default, that is, the first 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 code will not be posted. The following are two commonly used processing methods.
Use
<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 2:
<select id="projectPorperty" name="projectPorperty"> <option value="1">实施</option> <option value="0">研发</option> </select> <script> form.projectPorperty.value = '${user.projectPorperty}'; </script>
Static variable method:
<!-- 实现select标签回显 --> 1.<select name="curStatus" value="${curStatus}"> <option value="0">-请选择-</option> <option value="1" <c:if test="${'1' eq curStatus}">selected</c:if> >男</option> <option value="2" <c:if test="${'2' eq curStatus}">selected</c:if> >女</option> </select>
The above is the detailed content of What to use to write drop-down box in jsp page. For more information, please follow other related articles on the PHP Chinese website!