【发布时间】:2021-02-17 08:08:14
【问题描述】:
我会请求您帮助使用 Spring MVC 标记为隐藏的表单字段分配值,但是它不采用变量值,而是将变量作为文本,我是这项技术的新手,所以不太确定我在哪里我错了。
var subEnt = $("#selEntity").val(); //gets data from dynamic dropdown within the form
var inpmarkup='<form:hidden path="bypassModel.selectedEntities" value="' +subEnt+ '"/>'; //create the inner html
$("table tbody").append(inpmarkup); //add the inner html to the DOM
console.log("inpmarkup=> ",inpmarkup); //console log the inpmarkup
在控制台窗口中,当我为 inpmarkup 执行 console.log 时,它给了我
inpmarkup=> <input id="selectedEntities" name="selectedEntities" value=" +subEnt+ " type="hidden" value=""/>
当查看 DOM 时,它会显示以下内容:
<input id="selectedEntities" name="selectedEntities" value=" +subEnt+ " type="hidden">
非常感谢您的帮助。 谢谢。
【问题讨论】:
-
你检查
$("#selEntity").val();是否有任何价值?上面的代码也可以正常工作。在这里,工作小提琴:jsfiddle.net/9q62yo0u -
是的,$("#selEntity").val() 正在获取价值,console.log 打印它,当我将它添加到表中的
元素时,它显示价值。 非常感谢 Swati 和 BalusC。
标签: javascript jquery spring spring-mvc jsp