Home  >  Article  >  Web Front-end  >  Introductory example of JavaScript sub method (display string as subscript)_Basic knowledge

Introductory example of JavaScript sub method (display string as subscript)_Basic knowledge

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

JavaScript sub method

The

sub method returns a subscript string defined using the HTML sub tag attribute. Its syntax is as follows:

Copy code The code is as follows:

str_object.sub()

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

sub method instance

Copy code The code is as follows:


Run this example, output:

Copy code The code is as follows:

Script HouseEvery bit of progress is a solid footprint on our road to success

Tip: This method returns the subscript string defined using the HTML sub tag, even though this method cannot directly change the string to a subscript style. If you want to dynamically change the element font to a subscript style, you can refer to the following example:

Change the font text top and bottom alignment (superscript/subscript)

Copy code The code is as follows:





Subscript style Superscript style



Script HouseEvery bit of progress is a solid footprint on our road to success




In this example, JavaScript is used to control the text CSS vertical-align style to dynamically change the upper and lower alignment (superscript/subscript) of the font text.

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