jQuery获取随机颜色的实例代码
网络编程 2021-07-04 16:45www.168986.cn编程入门
这篇文章主要介绍了jQuery获取随机颜色的实例代码,非常不错,具有一定的参考借鉴价值,感兴趣的朋友跟随狼蚁SEO长沙网络推广来学习吧
1.js
//获取十六进制颜色 function randomColor1(){ var r = Math.floor(Math.random()256); var g = Math.floor(Math.random()256); var b = Math.floor(Math.random()256); if(r < 16){ r = "0"+r.toString(16); }else{ r = r.toString(16); } if(g < 16){ g = "0"+g.toString(16); }else{ g = g.toString(16); } if(b < 16){ b = "0"+b.toString(16); }else{ b = b.toString(16); } return "#"+r+g+b; } $("h3").css("color",randomColor1());
2.html
.<h3>获取任意颜色</h3>
效果
狼蚁网站SEO优化在看一段代码关于js几种生成随机颜色方法
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <button id="btn1">调用第一种</button> <button id="bnt2">调用第二种</button> <button id="btn3">调用第三种</button> <script> var btn1=document.getElementById('btn1'); btn1.onclick=function(){ document.body.style.background=bg1() }; var btn2=document.getElementById('bnt2'); btn2.onclick=function(){ document.body.style.background=bg2(); }; var btn3=document.getElementById('btn3'); btn3.onclick=function(){ document.body.style.background=bg3(); }; function bg1(){ return '#'+Math.floor(Math.random()256).toString(10); } function bg2(){ return '#'+Math.floor(Math.random()0xffffff).toString(16); } function bg3(){ var r=Math.floor(Math.random()256); var g=Math.floor(Math.random()256); var b=Math.floor(Math.random()256); return "rgb("+r+','+g+','+b+")";//所有方法的拼接都可以用ES6新特性`其他字符串{$变量名}`替换 } </script> </body> </html>
以上所述是长沙网络推广给大家介绍的jQuery获取随机颜色的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,长沙网络推广会及时回复大家的。在此也非常感谢大家对狼蚁SEO网站的支持!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指