textbox - 如何获取所选值以在百里香中输入文本框
问题描述
下拉菜单中的 onchange,dist_nm 应该反映在文本框中。有人可以帮忙吗?
<select id="editDistName" th:field="*{districts}" th:onchange="selectedDistName();">
<option value="default">Select the District </option>
<option th:each="dist : ${districts}" th:value="${dist.dist_id}"
th:text="${dist.dist_nm}" th:selected="${dist.dist_nm}"/>
</select>
<input type="text" class="form-control" id="dist_nm" name="dist_nm"/>
解决方案
1.)我不认为你的 th:selected="..."-attribute 有任何影响。
2.)试试这个js代码(使用jquery):
function selectedDistName()
{
let txt = $("#editDistName option:selected").text();
console.log(txt);
$("#dist_nm").val(txt);
}
如果您不使用 jquery,请发表评论。
推荐阅读
- c# - 即使当前视图和其他视图已显示,也无法找到视图
- java - bean 构造函数中的 Java 值注入
- python - python请求中找不到404的解决方案吗?
- salesforce - 在我的单元测试期间,断言语句在测试类中失败
- php - axios.delete 的“尝试获取非对象的属性‘参数’”。后端:PHP 前端:React
- angular - 角度数据未定义
- scala - 如何处理在scala中解析json的异常
- vue.js - Vuejs,当我在商店模块中访问它时,为什么 this.$store.state.route.params.activityId 未定义
- html - 输入元素在聚焦时覆盖按钮
- python - 如何从 [c_api.h] 向 TF_SessionRun 提供训练数据