2

I'm using knockout to set the background image on some divs:

<div class="values" data-bind="foreach: values" >
  <div class="cvsection" data-bind="style: {'background-image': backgroundimg}" style="background-repeat: no-repeat; background-size:100%;background-repeat: no-repeat; background-position: center bottom;">

    <!-- Stuff inside the div -->   
  </div>
</div>

Where in my viewmodel, each value() has a property like:

backgroundimg: 'url(i/img.jpg)'

The background images show up as expected in Chrome and IE9, but not Firefox 15 or IE8. I don't see any javascript errors in the console or anything.

Do you think this is a problem with knockout, or some other CSS issue? Any help would be appreciated!

4

2 回答 2

8

我想你的片段应该是

<div class="values" data-bind="foreach: values" >
  <div class="cvsection" data-bind="style: {backgroundImage: backgroundimg}" style="background-repeat: no-repeat; background-size:100%;background-repeat: no-repeat; background-position: center bottom;">

    <!-- Stuff inside the div -->   
  </div>
</div>

“背景图像”已更改为背景图像

根据文件

如果要应用字体粗细或文本装饰样式,或名称不是合法 JavaScript 标识符的任何其他样式(例如,因为它包含连字符),则必须使用该样式的 JavaScript 名称。

于 2012-09-26T19:35:24.167 回答
2

看看这里,当它说:

注意:应用名称不是合法 JavaScript 变量名称的样式

如果要应用字体粗细或文本装饰样式,或名称不是合法 JavaScript 标识符的任何其他样式(例如,因为它包含连字符),则必须使用该样式的 JavaScript 名称。例如,

不要写 { font-weight: someValue }; 写 { fontWeight: someValue }

不要写 { text-decoration: someValue }; 写 { textDecoration: someValue }

因此,如果要应用 css 规则“背景图像”,则必须在淘汰赛的样式绑定中写入“背景图像” 。

文档总是能解决问题;)

于 2013-07-26T10:00:05.283 回答