【发布时间】:2019-05-08 03:55:20
【问题描述】:
我正在尝试动态设置<div> 的宽度值,该<div> 在我用来生成一些PDF 的HTML 模板中用作彩色条。
我可以使用{{my_value}} 之类的东西设置其他值,但在样式中使用类似的值似乎不起作用。
我尝试过使用width: {{my_value}}%。
我还尝试通过将 div 分配给一个类来设置值,即.divClass { "width": {{my_value}} }
HTML 模板:
<!-- Change the width dynamically to same value as {{my_value}} -->
<div style="width: 45% !important;">
<!-- Dynamic percentage below and above -->
<div style="padding-left:8px;">{{my_value}}%</div>
</div>
JS 文件包含以下内容
// Get the value from the POST
var val1 = req.body.val1;
//replace the value in the template
templateHtml = templateHtml.replace('{{my_value}}', val1);
如果 POST val1 = 20% 我希望看到彩色条 <div> 仅填充了 20%,并且上面也写有百分比。
就目前而言,我可以将百分比写入条形图,但它只是用颜色填充整个条形图。
【问题讨论】: