【问题标题】:Run JS Without Button无按钮运行 JS
【发布时间】:2020-07-10 06:05:05
【问题描述】:

我有一个使用 jinja 的条件,我想在满足该条件时运行一段 js 代码。

这是我的代码:

M.toast({html: 'I am a toast!', classes: 'rounded'})
{% if condition %}
    run js right here
{% endfor %}

编辑:顺便说一句,我正在使用 materializecss toasts。链接:https://materializecss.com/toasts.html

【问题讨论】:

  • 我的是 if 条件。我可以把 html 放在我的 if 条件中,所以我可以把 js.我想知道如何执行 js 命令,没有 html 中的按钮。我想这样做的原因是因为我正在使用 jinja 条件。

标签: javascript html jinja2


【解决方案1】:

我猜你可以编写你的 javascript 代码在脚本标签中运行,以便在页面加载时执行:

{% if condition %}
    <script type="text/javascript">
      //js code goes there
    </script>
{% endfor %}

【讨论】:

  • 非常感谢!真的帮到我了!
猜你喜欢
  • 1970-01-01
  • 2019-08-27
  • 2015-10-16
  • 2018-09-15
  • 2022-11-23
  • 2018-09-25
  • 1970-01-01
  • 1970-01-01
  • 2020-11-26
相关资源
最近更新 更多