JavaScript sub method
The sub method returns a subscript string defined using the HTML sub tag attribute. The syntax is as follows:
The code copy is as follows:
str_object.sub()
Tip: This method does not comply with ECMA standards and is not recommended for use.
sub method example
The code copy is as follows:
<script language="JavaScript">
document.write( 'Wulin.com' + 'Every little progress is a solid footprint on our road to success'.sub() );
</script>
Run this example and output:
The code copy is as follows:
Every little progress in Wulin.com is a solid footprint on our road to success
Tip: This method returns a subscript string defined using the HTML sub tag, that is, using this method, you cannot directly change the string to the subscript style. If you want to dynamically change the element font to the subscript style, you can refer to the following example:
Change the up and down alignment of font text (superscript/subscript)
The code copy is as follows:
<html>
<script language="JavaScript">
function changFont( x ){
document.getElementById("sub_title").style.verticalAlign = x;
}
</script>
<body>
<p>
<a onClick="changFont('sub');">Subscript style</a> <a onClick="changFont('super');">Superscript style</a>
</p>
<p>
Wulin.com<span id="sub_title">Every little progress is a solid footprint on our road to success</span>
</p>
</body>
</html>
In this example, JavaScript controls the text CSS vertical-align style to dynamically change the up and down alignment of font text (superscript/subscript).