【发布时间】:2019-10-30 13:56:56
【问题描述】:
我在前端有下拉菜单。它是用 bootstrap 和 thymeleaf 创建的。我只需要显示对象的名称,但选择了 ID。 使用 JQuery 获取 th:text 值不是问题,但我需要 th:value。而且做不到。
html代码:
<div class="btn-group dropdown">
<button type="button" class="btn btn-outline-secondary dropdown-toggle btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Enable tollsystem</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item dropdown-item-disabled-tollsystem"
id="disabled-tollsystem"
th:each="myobject:${myobjects}"
th:if="${myobject.disabled == true}"
th:text="${myobject.name}"
th:value="${myobject.Id}"
></a>
</div>
JQuery 代码:
$("body").on("click", ".dropdown-item.dropdown-item-disabled-tollsystem", function (event) {
var system = $(this).text();
console.log(system);
});
var system = $(this).text(); 获取名称。我怎样才能得到身份证?
【问题讨论】:
-
$(this).val() 显示为空
-
你可以使用
$(this).attr('id') -
请将我的答案标记为已回答:)
标签: jquery twitter-bootstrap thymeleaf