Home >Web Front-end >JS Tutorial >A js random color script (for label pages, can also be used for any page)_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 19:08:481153browse

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>
Statement:
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