JAVA,点击按钮切换背景图片,怎么做(用repaint()切换),能给个代码作例子吗
2个回答
展开全部
这段代码和你提的问题类似,不过这个是直接自动切换的!你只需要把自动的哪块换个按钮,在换个触发事物的函数就可以了!
<script>
var count = 0;
var pics = new Array("a.jpg","b.jpg","c.jpg","d.jpg");
function changePic()
{
//得到img
var myPic = document.getElementById('pic');
//根据对象 修改DOM元素的属性
myPic.src = pics[count];
count++;
if(count == pics.length)
{
count = 0;
}
//调用函数
setTimeout('changePic()',2000);
}
</script>
</HEAD>
<BODY onload="changePic()">
<img src="#" height="500" width="500" id="pic"/>
</BODY>
<script>
var count = 0;
var pics = new Array("a.jpg","b.jpg","c.jpg","d.jpg");
function changePic()
{
//得到img
var myPic = document.getElementById('pic');
//根据对象 修改DOM元素的属性
myPic.src = pics[count];
count++;
if(count == pics.length)
{
count = 0;
}
//调用函数
setTimeout('changePic()',2000);
}
</script>
</HEAD>
<BODY onload="changePic()">
<img src="#" height="500" width="500" id="pic"/>
</BODY>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询