javascript 使用 spring-thymeleaf 访问 textarea
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27839870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
access textarea with spring-thymeleaf
提问by Paule Wasgehtsiedenndasan
following Problem: I try to change the text of a textarea.
I'm using Sping and Thymeleaf.
Right now my Code looks like this:
以下问题:我尝试更改 textarea 的文本。
我正在使用 Sping 和 Thymeleaf。
现在我的代码如下所示:
Spring:
春天:
[...]
modelMap.addAttribute("Email", "035and so on");
modelMap.addAttribute("Notes", "Please take this text and use it!");
[...]
Thymeleaf:
百里香:
[...]
<div class="col-sm-6 col-md-6 col-lg-6">
<input name="Tel" class="form-control" placeholder="Telefonnummer"
th:value="${Tel}" style="width: 100%;" />
</div>
<div><textarea class="form-control" rows="12"
style="margin-top: 10px;" placeholder="Sonstige Bemerkungen"
name="notes" th:field="*{Notes}">
</textarea></div>
[...]
the telephone String works fine, but i dont know how to access the
Textarea. Would be glad if someone could help me.
电话字符串工作正常,但我不知道如何访问
Textarea。如果有人可以帮助我,我会很高兴。
回答by Amy Slawson
I had the same problem finding that textarea does not support a value attribute. If you are trying to insert thymeleaf variable into a html textarea, you can use text inlining. So something like this...
我发现 textarea 不支持 value 属性时遇到了同样的问题。如果您尝试将 thymeleaf 变量插入 html textarea,则可以使用文本内联。所以像这样的事情......
<div><textarea class="form-control" rows="12"
style="margin-top: 10px;" placeholder="Sonstige Bemerkungen"
name="notes" th:inline="text">[[${Notes}]]
</textarea></div>
Good reference here: http://loongest.com/uncategorized/thymeleaf/
这里有很好的参考:http: //loongest.com/uncategorized/thymeleaf/
回答by Shafin Mahmud
you can just use th:text
it will work too. Bu I prefer @Amy's way.
你也可以使用th:text
它。但是我更喜欢@Amy 的方式。
回答by Pthahnil
I'm having the same problem, you can try th:text, it works for me.
我遇到了同样的问题,你可以试试 th:text,它对我有用。
th:text="${Notes}"