简体   繁体   English

选择下拉“选定”选项不会突出显示

[英]Select drop down “selected ”option not getting highlighted

I'm using Spring MVC and setting the list of counties to the request. 我正在使用Spring MVC,并将县列表设置为请求。 I set the list to the page request but the "selected" option is not getting highlighted on the HTML page. 我将列表设置为页面请求,但“选择的”选项在HTML页面上未突出显示。

My Controller code is as follows: 我的控制器代码如下:

//Populate drop down selection with list of counties ArrayList<County> counties = countyInformation.getCounties(State, Zip); request.setAttribute("counties", counties);

My JSP code is as follows: 我的JSP代码如下:

 <form:select class="form-control" path="counties">
        <form:option value="Select County"></form:option> 
        <form:options items="${countiesList}" itemValue="countyFipsId" itemLabel="countyName" /> 
 </form:select>

I have also tried this : 我也尝试过这个:

 <select id="county" name="county">
    <option value="">Select County</option>
     <c:forEach items="${counties}" var="county">

                    <c:choose>
                        <c:when test="${county == selectedCountyId}">
                            <option value="${county.countyId}" selected="selected">${county.countyName}</option>
                        </c:when>
                        <c:otherwise>
                            <option value="${county.countyId}" >${county.countyName}</option>
                        </c:otherwise>
                    </c:choose>

                </c:forEach>
            </select>

Is there any bug in the Spring / Browser rendering? Spring /浏览器渲染中是否存在任何错误? Currently, the selected option shows up in the dev toolbar, but the option itself is not highlighted. 当前,所选选项显示在开发工具栏中,但选项本身未突出显示。 It doesn't come into focus on the page 它没有集中在页面上

Is there a jQuery / JavaScript equivalent solution for this? 是否有jQuery / JavaScript等效的解决方案? Any help greatly appreciated. 任何帮助,不胜感激。 Thank you 谢谢

Your attribute in the controller is set to "counties" , but your form:options items is set to ${countiesList} . 控制器中的属性设置为"counties" ,但是form:options items设置为${countiesList} Try changing it to ${counties} . 尝试将其更改为${counties}

You might also want to try wrapping your form:select block in a spring:bind tag. 您可能还想尝试在spring:bind标签中包装form:select块。

<spring:bind path="controllerName.counties">
    <form:select class="form-control" path="controllerName.counties">
        <form:option value="Select County"></form:option> 
        <form:options items="${counties}" itemValue="countyFipsId" itemLabel="countyName" /> 
    </form:select>
</spring:bind>

EDIT: After reading your post again, I'm not sure if my solution is what you're after. 编辑:再次阅读您的文章后,我不确定我的解决方案是否是您的追求。 Are you looking for the browser to recognize the selected list item after it is selected from the dropdown? 从下拉列表中选择列表项之后,您是否正在寻找浏览器来识别所选列表项? If that's the case, you'll have to add an onClick() handler via javascript in order to process the request. 在这种情况下,您必须通过javascript添加onClick()处理函数才能处理请求。 The selected item won't be recognized until some kind of explicit action takes place (like a js function, a post, or a get). 在进行某种类型的显式操作(例如js函数,发布或获取)之前,所选项目将不会被识别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM