【问题标题】:EJS Variable in HTML Style attributeHTML Style 属性中的 EJS 变量
【发布时间】:2020-11-02 04:18:09
【问题描述】:

我正在尝试将一个变量传递给这个 div 的样式属性:

<div class="progress progress-sm">
      <div class="progress-bar bg-success" aria-valuenow="<%=Math.round((resp.length / 14) * 100) %>" aria-valuemin="0" aria-valuemax="100" style="width: <%=Math.round((resp.length / 14) * 100) %>%;"><span class="sr-only"><%=Math.round((resp.length / 14) * 100) %>%</span></div>
</div>

但不幸的是,它说的是预期的属性值,所以我假设我不能在这里传递变量。有解决办法吗?我可以在其他地方使用相同的确切变量,所以不是那样。

【问题讨论】:

    标签: node.js express ejs


    【解决方案1】:

    我找到的解决方案是在底部添加一些 javascript,如下所示:

       <script>
        document.getElementById('prog').style.setProperty('width', '<%=Math.round((resp.length / 14) * 100) %>%')
    </script>
    

    【讨论】:

      猜你喜欢
      • 2021-06-18
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 2020-12-21
      • 2021-06-29
      • 2011-04-09
      • 2019-01-30
      相关资源
      最近更新 更多