时间:2021-05-26
大家好!
今天分享一个在 JavaScript中,实现一个鼠标移入可以随机变换颜色。
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title></title> <style> span{ display: block; width: 80px; height: 80px; border: 1px solid #000000; float: left; } </style> </head> <body> <div> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> <span></span><span></span><span></span><span></span><span></span><span></span> </div> <script type="text/javascript"> var a=document.getElementsByTagName("span"); for(var i=0;i<=a.length;i++){ a[i].onmouseover=function(){ this.style.backgroundColor="#"+Math.floor(Math.random()*16777215).toString(16); } } </script> </body></html>如下是代码运行后在这里插入图片描述
总结
到此这篇关于JavaScript实现鼠标移入随机变换颜色的文章就介绍到这了,更多相关JS鼠标移入随机变换颜色内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
AE中想要制作一个文字随机变换颜色的动画效果,该怎么制作呢下面我们就来看看详细的教程。软件名称:AdobeAfterEffects2020v17.0.4.59免
本文实例讲述了JavaScript实现的背景自动变色代码。分享给大家供大家参考,具体如下:这里演示JavaScript实现网页背景自动变色,自己变换颜色,设定时
本文介绍了JavaScript检测鼠标移动方向的方法,涉及javascript鼠标操作的相关技巧,供大家参考,具体内容如下判断鼠标移入方向的功能函数functi
本文实例讲解了基于javascript实现随机颜色变化效果,分享给大家供大家参考,具体内容如下随机颜色变化效果#thediv{width:100px;heigh
采用Javascript实现,用鼠标点击相应颜色,动态改变网页背景颜色这是截图相应的Javascript源代码为:复制代码代码如下:varhex=newArra