[html]<script language="JavaScript">
function RandomColorLink(link, text) {
var colors = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
var result_color = '#';
var symbols = 0;
for (var i = 1; i < 7; i++) {
var random = Math.floor(Math.random() * 12);
if (symbols < 3) result_color += colors[random + 4];
else if (symbols < 14) result_color += colors[(random < symbols - 2) ? random : random + 4];
else result_color += colors[random];
}
document.write('<a href="'+link+'" style="color: '+result_color+'">'+text+'</a><br>');
}
</script>
<script language="JavaScript"> RandomColorLink('https://blog.topp.ru', 'Пример работы функции'); </script>
[/html]
Скрипт:
<script language="JavaScript"> function RandomColorLink(link, text) { var colors = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); var result_color = '#'; var symbols = 0; for (var i = 1; i < 7; i++) { var random = Math.floor(Math.random() * 12); if (symbols < 3) result_color += colors[random + 4]; else if (symbols < 14) result_color += colors[(random < symbols - 2) ? random : random + 4]; else result_color += colors[random]; } document.write('<a href="'+link+'" style="color: '+result_color+'">'+text+'</a><br>'); } </script>
Выводим ссылку так:
<script language="JavaScript"> RandomColorLink('https://blog.topp.ru', 'Пример работы функции'); </script>
- Подпись автора