JavaScript Bold Method
The LastIndexOf method returns the bold string defined using the HTML b tag. The syntax is as follows:
Copy Code code as follows:
Tip: This method does not conform to the ECMA standard and is not recommended for use.
Bold Method Instance
Copy Code code as follows:
<script language= "JavaScript" >
var str = "Www.jb51.net";
document.write (Str.bold ());
</script>
Run the example and output:
Copy Code code as follows:
Tip: This method returns the bold string defined using the HTML b tag, which means that using this method does not dynamically change the font of the page element to bold. If you want to dynamically change the element font to bold, refer to the following example:
Extended reading: Changing page element font size
Copy code code as follows:
<script language= "JavaScript" >
function Changfont (x) {
var font_style = x;
var Article = document.getElementById ("article");
if (typeof Font_style = = "string") {
Article.style.fontWeight = Font_style;
} else {
Article.style.fontSize = Font_style;
}
}
</script>
<body>
<p>
<a onclick= "Changfont (' normal ');" > Normal </a> <a onclick= "Changfont (' bold ');" > Bold </a>
<a onclick= "Changfont (14);" > S </a> <a onclick= "Changfont (18);" > Large </a>
</p>
<p id= "article" >
I am some words ... <br/>
Some Text ...
</p>
</body>
In this example, by using JavaScript to control the font CSS style, the display font (id= "article") can be switched on in real time between bold, normal, small, and large fonts.