JavaScript methods for obtaining random RGB colors and hexadecimal colors

Source: Internet
Author: User
<div id= "Console" > Online trading Platform Success tips: from Ebay to Yelp to Uber</div><script type= "Text/javascript" >var Consoledom = document.getElementById ("console"); ConsoleDom.style.color = RandomColor1 ();//Get RGB type color  IE7 does not support function Randomcolor () {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+ ")";} Gets the hexadecimal color 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 <) {r = "0" +r.tostring (16);} Else{r = r.tostring (16);} if (g <) {G = "0" +g.tostring (16);} Else{g = g.tostring (16);} if (b < c) {B = "0" +b.tostring (16);} Else{b = b.tostring (16);} Return "#" +R+G+B;} /* Conversion number.tostring (2); Convert to 2\8\10\16*/function test () {//console.log (new number (). toString (16));} Test ();</script>

  

JavaScript methods for obtaining random RGB colors and hexadecimal colors

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.