【发布时间】:2013-12-24 13:41:29
【问题描述】:
所以,我得到了这个 div:
<div id="pictures" style="
position: absolute;
bottom: 0px; left: 0;
width: 100%;
background-image: url(inhalt/lan7071.jpg);
background-position: bottom;
background-size: contain;
background-repeat: no-repeat;
z-index: 1;
height: -moz-calc(100% - 170px);
height: -webkit-calc(100% - 170px);
height: -o-calc(100% - 170px);"
></div>
在同一个 .htm 的其他地方单击表格中的文本我想更改此 div 的背景 url:
<table>
<tr>
<td ><a onclick="document.getElementById('pictures').style.background='url(content/image2.jpg)'">Image 2<a></td>
<td ><a onclick="document.getElementById('pictures').style.background='url(content/image3.jpg)'">Image3<a></td>
</tr>
</table>
点击“图片2”后,背景确实发生了变化,而且在整个div上也重复了,我猜是“ background-size: contains; background-repeat: no-repeat;”被忽略。
有没有什么小而简单的 jQuery 方法可以在单击另一个 div 后简单地更改另一个 div 的背景 URL?我还希望新背景保留早期的规范,如无重复、大小包含等......
我喜欢能够在每个链接之前或之后添加一个简短的 js 代码并在网站的其他地方拥有一个 js 函数的想法。
jsfiddle 在这里:http://jsfiddle.net/R7gEH/
非常感谢,圣诞快乐!
【问题讨论】:
标签: html background repeat