如何在动态调用JQuery函数的情况下呈现内部的数据? $(“#添加准备过程列表”)。在(“单击”,函数(){ var索引=$(“#准备过程列表”).find(“textarea”).length; 变量elementToAdd=''+ ' '; $(“#准备过程列表”).append(elementToAdd); });
这是我们在ui页面中调用JQuery函数的示例代码,因此文本区域将添加到html页面如何在动态调用JQuery函数的情况下呈现内部的数据? $(“#添加准备过程列表”)。在(“单击”,函数(){ var索引=$(“#准备过程列表”).find(“textarea”).length; 变量elementToAdd=''+ ' '; $(“#准备过程列表”).append(elementToAdd); });,jquery,html,thymeleaf,Jquery,Html,Thymeleaf,这是我们在ui页面中调用JQuery函数的示例代码,因此文本区域将添加到html页面 此处:属性未解析为标签或占位符。要解析占位符,您需要将代码更改为: $("#addPreparationProcessList").on("click", function () { var index = $("#preparationProcessList").find("textarea").length; var elementToAdd = '<div class="row"
此处:属性未解析为标签或占位符。要解析占位符,您需要将代码更改为:
$("#addPreparationProcessList").on("click", function () {
var index = $("#preparationProcessList").find("textarea").length;
var elementToAdd = '<div class="row"><div class="col-lg-8"><div class="input-group input-group-lg"><span class="input-group-addon" th:placeholder="#{placeholder.whatiscooking_placeholder}"></span>' +
'<textarea type="text" style="height:80px;" id="preparationProcessList' + index + '.preparationProcess" class="form-control top_margin_small"
th:placeholder="#{placeholder.whatiscooking_placeholder}"
placeholder="What is Cooking"></textarea> </div> </div>';
$("#preparationProcessList").append(elementToAdd);
});
//你还有什么
$(#addPreparationProcessList”)。在(“单击”,函数(){
var whatIsCookingPlaceholder=/*[[{placeholder.whatiscooking{u placeholder}]]*/'test';
var索引=$(“#准备过程列表”).find(“textarea”).length;
变量elementToAdd=''+
' ';
$(“#准备过程列表”).append(elementToAdd);
});
查看部分文档以了解更多信息谢谢您的回复,我需要在调用函数时解析thymeleaf标记,或者从.properties文件获取它。提前感谢。您需要解决Thymeleaf标签是什么意思?根据我从代码中看到的情况,您正在使用
th:placeholder
来动态设置占位符。这种语法在Javascript中不起作用。您需要使用我在上面展示的/*[[#{placeholder.whatiskooking\u placeholder}]]*/
构造
<script th:inline="javascript">
//whatever else you have
$("#addPreparationProcessList").on("click", function () {
var whatIsCookingPlaceholder = /*[[#{placeholder.whatiscooking_placeholder}]]*/ 'test';
var index = $("#preparationProcessList").find("textarea").length;
var elementToAdd = '<div class="row"><div class="col-lg-8"><div class="input-group input-group-lg"><span class="input-group-addon" placeholder="' + whatIsCookingPlaceholder + '"></span>' +
'<textarea type="text" style="height:80px;" id="preparationProcessList' + index + '.preparationProcess" class="form-control top_margin_small"' +
'placeholder="' + whatIsCookingPlaceholder + '"></textarea> </div> </div>';
$("#preparationProcessList").append(elementToAdd);
});
</script>