JavaScript+Thymeleaf-选择onchange
我在my thymeleaf上下文中有一个对象服务列表,我的页面上有以下内容:JavaScript+Thymeleaf-选择onchange,java,javascript,jquery,html,thymeleaf,Java,Javascript,Jquery,Html,Thymeleaf,我在my thymeleaf上下文中有一个对象服务列表,我的页面上有以下内容: <select id="inputService" name="idService" size="1"> <option th:each="service : ${services}" th:text="${service.name}" th:value="${service.idService}"/> </select> <p id="selectedService
<select id="inputService" name="idService" size="1">
<option th:each="service : ${services}" th:text="${service.name}" th:value="${service.idService}"/>
</select>
<p id="selectedServiceLimits"></p>
服务中的每个对象都包含minAmount和maxantum字段。如何在selectbyjavascript中将所选服务的这两个字段打印到p元素中?当文档准备就绪时,如何打印所选选项的这两个字段
谢谢
<script th:inline="javascript">
/*<![CDATA[*/
function showLimits() {
var services = /*[[${services}]]*/ null;
var selectedIndex = $("#inputService option:selected").index();
var service = services[selectedIndex];
$("#amountLimits").text("Мин. сумма: " + service.amountMin + ", макс. сумма: " + service.amountMax);
}
$(function() { showLimits(); });
/*]]>*/
</script>
<select id="inputService" name="idService" size="1" onChange="showLimits()">
这就是解决方案这对于这个特定的用例非常有效。原始问题中的标记的id为selectedServiceLimits,因此,如果使用此解决方案,您应该将提供的javascript的amountLimits更改为selectedServiceLimits,以处理您先前存在的html