javascript - 如何在具有 src 的标签中附加 thymeleaf 变量?
问题描述
似乎无法为此找到正确的语法?
<img id='barcode' src="https://api.qrserver.com/v1/create-qr-code/?data="'+ ${var.membervar} + "'+&size=100x100" alt="" title="HELLO" width="50" height="50" />
解决方案
你应该让 Thymeleaf 知道你想src
使用th:src
. 像这样的东西会起作用......
<img id='barcode' th:src="'https://api.qrserver.com/v1/create-qr-code/?data='+ ${var.membervar} + '&size=100x100'" alt="" title="HELLO" width="50" height="50" />
但是对于完全限定的 URL,您应该使用Thymeleaf 链接 URL,其中将为您的所有查询参数应用适当的编码。例如 ...
<img id='barcode' th:src="@{https://api.qrserver.com/v1/create-qr-code/(data=${var.membervar},size='100x100')}" alt="" title="HELLO" width="50" height="50" />
推荐阅读
- c - 我的链接列表正在打印我的文本文件中所有元素的最后一个单词
- android - fragment.xml 中的 DrawerLayout 未在主页图标单击时显示
- java - IllegalStateException:相同的线程,不同的源(GUI)
- angular - angular 5 根据另一个字段的值有条件地验证字段
- sonos - Oauth2 进程中的错误:请求的资源上不存在“Access-Control-Allow-Origin”标头
- node.js - json数组中的节点分页
- azure-active-directory - LoginAsync 使用访问令牌和 MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory
- angular - 离子 4 标签放置
- html - 只需将样式应用于 IE/Edge
- openssl - OpenSSL 警报编号 40