当用户翻过链接时,我正试图在div上换出背景图片。
我做错了什么?这不起作用。
<style>
#divToSwap {
background-image: url(black.jpg);
height: 150px;
width: 150px;
}
</style>
</head>
<body>
<div id="divToSwap"></div>
<div>
<ul>
<li><a href="#"
onmouseover="document.getElementById('divToSwap').backgroundImage='url(red.jpg)';"
onmouseout="document.getElementById('divToSwap').backgroundImage='url(black.jpg)';">
Red</a></li>
<li><a href="#"
onmouseover="document.getElementById('divToSwap').backgroundImage='url(blue.jpg)';"
onmouseout="document.getElementById('divToSwap').backgroundImage='url(black.jpg)';">
Blue</a></li>
<li><a href="#"
onmouseover="document.getElementById('divToSwap').backgroundImage='url(green.jpg)';"
onmouseout="document.getElementById('divToSwap').backgroundImage='url(black.jpg)';">
Green</a></li>
</ul>
</div>
答案 0 :(得分:0)
尝试,例如
document.getElementById('divToSwap').style.backgroundImage='url(black.jpg)';
答案 1 :(得分:0)
使用
document.getElementById('divToSwap').style.backgroundImage=...
而不是
document.getElementById('divToSwap').backgroundImage=....
答案 2 :(得分:0)
.style
缺失:
onmouseover="document.getElementById('divToSwap').style.backgroundImage='url(red.jpg)';"