Home > Web Front-end > JS Tutorial > body text

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

PHPz
Release: 2018-09-30 14:32:35
Original
2417 people have browsed it

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()
Copy after login

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

italics method instance

<script language="JavaScript">
var str = "m.sbmmt.com";
document.write( str.italics() );
</script>
Copy after login

Run this example, output:

m.sbmmt.com

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!