话不多说,请看代码
<!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>
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持移动技术网!
如对本文有疑问, 点击进行留言回复!!
同事牛逼啊,写了个隐藏 bug,我排查了 3 天才解决问题!
【JavaScript笔记(一)】万丈高楼平地起 - 基本概念篇
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
网友评论