为什么不能使用空格键为 HTML 元素插入样式?

问题描述 投票:0回答:1

我真的很挣扎于以下问题:

 <td class="left {{tableStyle}}" {{background}} >{{value}}</td>

还有我的 JS 代码:

   {'background':'style="background-color:red;"' }

这会导致 F无法在 'Element' 上执行 'setAttribute':'style="background-color:red;"' 不是有效的属性名称。

我尝试仅插入值(style={{data{{)等,但这甚至无法运行。

html css meteor spacebars
1个回答
0
投票

这是更正后的代码:

HTML:

<td class="left {{style}}" style="{{background}}">{{value}}</td>

JS:

{style: 'ClassName', background: 'background-color:red;', value: 'Content'}

你的代码的结构是错误的,它实际上是这样的:对于你在 HTML 中使用的每个属性,你应该这样提供一个属性-值对:

HTML:

{{Attribute}}
,JS:
{Attribute: 'Value'}

在您的原始代码中,如果忽略拼写错误,stylevalue参数没有值。

© www.soinside.com 2019 - 2024. All rights reserved.