Tự học JavaScript/Dòng văn bản

Tủ sách mở Wikibooks

Chức năng[sửa]

Dòng văn bản được dùng để biểu diển chữ và cách thể hiện chữ trong trang mạng

Cú pháp[sửa]

Khai báo dòng chữ

Var Text = "Hello, there"

Ghép thuộc tính dòng chữ

  • bold() - Chữ đậm
  • italic() - Chữ nghiên
  • big() - Chữ to
  • small() - Chữ nhỏ

Hiển thị dòng chữ với thuộc tính

document.write(Text.bold())

Thí dụ[sửa]

<!DOCTYPE html>
<html>
<body>
<script>
var txt = "Hello World!";
document.write("The original string: " + txt);
document.write("<p>Big: " + txt.big() + "</p>");
document.write("<p>Small: " + txt.small() + "</p>");
document.write("<p>Bold: " + txt.bold() + "</p>");
document.write("<p>Italic: " + txt.italics() + "</p>");
document.write("<p>Fixed: " + txt.fixed() + "</p>");
document.write("<p>Strike: " + txt.strike() + "</p>");
document.write("<p>Fontcolor: " + txt.fontcolor("green") + "</p>");
document.write("<p>Fontsize: " + txt.fontsize(6) + "</p>");
document.write("<p>Subscript: " + txt.sub() + "</p>");
document.write("<p>Superscript: " + txt.sup() + "</p>");
document.write("<p>Link: " + txt.link("http://www.w3schools.com") + "</p>");
document.write("<p>Blink: " + txt.blink() + " (does not work in IE, Chrome, Firefox or Safari)</p>");
</script>
</body>
</html>