我正在尝试做这样的事情:
<iframe th:src="'myFunction($videoUrl);'"></iframe>
其中 myFunction 是一个 jQuery 函数。我希望 src 值是函数的输出。
到目前为止,我已经尝试过了
<iframe th:src="'javascript:myFunction(\''+ ${videoUrl} +'\');'" ></iframe>
但是输出的不是函数的结果,而是以url为attributeL的函数。我猜这与 onClick 配合使用效果很好,但这不是我想要的。
这可能吗?
最佳答案
呃...thymeleaf/javascript 不能这样工作。与其尝试直接使用 javascript 函数设置源,不如在文档就绪 block 中执行此操作。例如这样的事情:
<script type="text/javascript" th:inline="javascript">
$(function() {
var url = [[${videoUrl}]];
$('#video').attr('src', myFunction(url));
});
<script>
<iframe id="video"></iframe>
关于javascript - 在 thymeleaf th :src 中使用 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43688861/