如何用Javascript做一个按钮点击一次变色一次,顺便拜个师傅,谢谢,在线等
http://blog.csdn.net/hello_l/article/details/50404586
改变自身颜色
function randomColor() { var colorNum = Math.round(Math.random() * 255); return colorNum; } var oBtn = document.getElementById('btn'); oBtn.onclick = function () { this.style.backgroundColor = 'rgb(' + randomColor() + ',' + randomColor() + ',' + randomColor() + ')'; }改变自身颜色
function randomColor() { var colorNum = Math.round(Math.random() * 255); return colorNum; } var oBtn = document.getElementById('btn'); oBtn.onclick = function () { this.style.backgroundColor = 'rgb(' + randomColor() + ',' + randomColor() + ',' + randomColor() + ')'; }
答案楼上给了,每次随机三原色的值。是妹子就收了^_^
徒弟你好:
代码如下:修改图片路径就可以了
<script type="text/javascript">
function showimg(obj){
if(obj.src=="http://bbs.blueidea.com/images/blue/newtopic.jpg"){
obj.src="http://bbs.blueidea.com/images/blue/reply.jpg";
}
else{
obj.src="http://bbs.blueidea.com/images/blue/newtopic.jpg";
}
}
</script>
<img src="http://bbs.blueidea.com/images/blue/newtopic.jpg" onclick="showimg(this)" />