javascript - 在 thymeleaf th :src 中使用 javascript

标签 javascript jquery thymeleaf

我正在尝试做这样的事情:

 <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/

相关文章:

javascript - jquery 自动完成 url 损坏

javascript - 模拟 vue 组件依赖

php - jquery 甘特图插件

java - Spring Boot 2.1 中热重载 Thymeleaf 模板和资源包

javascript - 通过表单提交创建ArrayList(Thymeleaf + Spring MVC)

javascript - jQuery 在其子元素上发生 mousedown 事件时拖动元素

javascript - 如何使用 if 语句用 JavaScript 更改 CSS?

javascript - 使用 JQuery 在悬停时放大图像的问题

javascript - ES6 Promise 相当于 jQuery Deferred 的 'always` 吗?

java - Spring 启动: Cannot access page html on localhost (404)