Home >Web Front-end >JS Tutorial >Introductory example of JavaScript fontcolor method (display string according to specified color)_Basic knowledge

Introductory example of JavaScript fontcolor method (display string according to specified color)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:33:361829browse

JavaScript fontcolor method

The

fontcolor method returns a string with color defined using the color attribute in the HTML font tag. Its syntax is as follows:

Copy code The code is as follows:

str_object.fontcolor( color )

Parameter description:

参数 说明
str_object 要操作的字符串(对象)
color 必需。颜色名(red)、RGB 值(rgb(255,0,0))或者十六进制数(#FF0000)

Tip: This method does not comply with ECMA standards and is not recommended.

fontcolor method instance

Copy code The code is as follows:


Run this example, output:

Copy code The code is as follows:

www.jb51.net

Tip: This method returns the string defined using the HTML color tag, even though this method cannot dynamically change the font color. If you want to dynamically change the font color of an element, you can refer to the following example:

Further reading: Change the font color of page elements

Copy code The code is as follows:



black red
blue



I am some text...

Some Text...




In this example, the color of the font (id="article") can be dynamically changed by controlling the font CSS style through JavaScript.

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