Home  >  Article  >  Web Front-end  >  Getting started with JavaScript italics method (display string in italics)

Getting started with JavaScript italics method (display string in italics)

PHPz
PHPzOriginal
2016-05-16 16:33:322466browse

This article mainly introduces the introductory examples of the JavaScript italics method. The italics method is used to display strings in italics. Friends in need can refer to

JavaScript italics method

The

italics method returns a (italicized) string defined using the HTML i tag attribute. The syntax is as follows:

str_object.italics()

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

italics method instance

<script language="JavaScript">
var str = "www.php.cn";
document.write( str.italics() );
</script>

Run this example, output:

www.php.cn

Tip: This method returns a string defined using the HTML i tag, even if you use this method, you cannot dynamically change the font to italic. If you want to dynamically change the element font to italic, you can refer to the following example:

Further reading: Change the page element font to italic

<html>
<script language="JavaScript">
function changFont( x ){
    document.getElementById("article").style.fontStyle = x;
}
</script>
<body>
<p>
<a onClick="changFont(&#39;normal&#39;);">正常</a> <a onClick="changFont(&#39;italic&#39;);">斜体</a>
</p>
<p id="article">
我是一些文字 ...<br />
Some Text ...
</p>
</body>
</html>

In this example, By controlling the font CSS font-style style through JavaScript, the font (id="article") can be dynamically changed to italic.

The above is the entire content of this chapter. For more related tutorials, please visit JavaScript Video Tutorial!

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

Related articles

See more