我在css中有一个div图像和另一个小图像。如果我点击小图片,我希望我的div图像改变。
如何为此编写脚本?
答案 0 :(得分:0)
var div=document.getElementById('yourDiv');
var height = div.style.height;
var width = div.style.width;
var enlargedHeight = height + *size to increase goes here*;
var enlargedWidth = width + *size to increase goes here*;
function grow() {
if (div) {
div.style.backgroundImage = 'url(newimage.gif)';
height=enlargedHeight;
width=enlargedWidth;
}
}
和你的div
<div id="yourDiv" onclick="grow();">
/*content*/
</div>
答案 1 :(得分:0)
只需编写一个onclick处理程序,如:
document.getElementById ('theSmallImageId').onclick = function{
document.getElementById ('TheDivId').style.backgroundImage = urlToTheNewImage;
};
我希望这有用。