String.fontcolor
JavaScript -> Objekty -> String -> metóda String.fontcolor
Syntax
jmeno_string.fontcolor(barva)
Popis
Príkaz jazyka JavaScript
Zpusobi, ze dany retezec je zobrazen specifikovanou barvou tak, jako by byl uveden v <FONT COLOR=color> tagu.
- jmeno_string je libovolny retezec nebo vlastnost existujiciho objektu.
- barva je retezec nebo vlastnost existujiciho objektu, ktery vyjadruje barvu jako hexadecimalni RGB triplet nebo je to jeden z retezcovych literalu uvedenych v Barvach.
Pouzivejte metodu fontcolor spolu s metodou write nebo writeln k formatovani a zobrazeni textu v dokumentu.
Pokud vyjadrite barvu jako hexadecimalni RGB triplet, musite pouzit format rrggbb. Napriklad, hexadecimalni RGB hodnota pro barvu salmon je red=FA, green=80 a blue=72, takze RGB triplet pro salmon je "FA8072".
Metoda fontcolor prebije hodnotu nastavenou vlastnosti fgColor.
Príklad
Nasledujici priklad pouziva metodu fontcolor ke zmene barvy retezce
var worldString="Hello, world"
document.write(worldString.fontcolor("maroon") +
" is maroon in this line")
document.write("<P>" + worldString.fontcolor("salmon") +
" is salmon in this line")
document.write("<P>" + worldString.fontcolor("red") +
" is red in this line")
document.write("<P>" + worldString.fontcolor("8000") +
" is maroon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FA8072") +
" is salmon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FF00") +
" is red in hexadecimal in this line")
document.write(worldString.fontcolor("maroon") +
" is maroon in this line")
document.write("<P>" + worldString.fontcolor("salmon") +
" is salmon in this line")
document.write("<P>" + worldString.fontcolor("red") +
" is red in this line")
document.write("<P>" + worldString.fontcolor("8000") +
" is maroon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FA8072") +
" is salmon in hexadecimal in this line")
document.write("<P>" + worldString.fontcolor("FF00") +
" is red in hexadecimal in this line")
Tento priklad produkuje stejny vystup jako nasledujici HTML:
<FONT COLOR="maroon">Hello, world</FONT> is maroon in this line
<P><FONT COLOR="salmon">Hello, world</FONT> is salmon in this line
<P><FONT COLOR="red">Hello, world</FONT> is red in this line
<P><FONT COLOR="8000">Hello, world</FONT> is maroon in hexadecimal in this line
<P><FONT COLOR="FA8072">Hello, world</FONT> is salmon in hexadecimal in this line
<P><FONT COLOR="FF00">Hello, world</FONT> is red in hexadecimal in this line
<P><FONT COLOR="salmon">Hello, world</FONT> is salmon in this line
<P><FONT COLOR="red">Hello, world</FONT> is red in this line
<P><FONT COLOR="8000">Hello, world</FONT> is maroon in hexadecimal in this line
<P><FONT COLOR="FA8072">Hello, world</FONT> is salmon in hexadecimal in this line
<P><FONT COLOR="FF00">Hello, world</FONT> is red in hexadecimal in this line
Pozri aj
String.fgColor