Home > Web Front-end > JS Tutorial > body text

A js random color script (for label pages, can also be used for any page)_javascript skills

WBOY
Release: 2016-05-16 19:08:48
Original
1120 people have browsed it

If you see someone asking for this, please post it. 237 bytes of stuff. Very small, right?
Add the following code in front of

in tag.asp.
Don’t ask such a simple question.
In fact, you can also add it to header.asp or footer.asp. But in this way, all the span areas of your entire page will be randomly colored.

Demo
http://www.hljsh.com/tag.asp
The effect is the same. But my demonstration is implemented using asp. What I posted was implemented using JS. The effect is the same.

Copy code The code is as follows:

<script> <br>var obj = document. getElementsByTagName("span"); <br>for(i=0;i<obj.length;i ) <BR>{ <BR>var str = "0123456789abcdef"; <BR>var t = "#"; <BR>for(j=0;j<6;j ) <BR>{t = t str.charAt(Math.random()*str.length);} <BR>obj[i].style.color=t; <BR>} <BR></script>


[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> var obj = document.getElementsByTagName("span"); for(i=0;i<obj.length;i++) { var str = "0123456789abcdef"; var t = "#"; for(j=0;j<6;j++) {t = t+ str.charAt(Math.random()*str.length);} obj[i].style.color=t; } </script>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template