JavaScript 字符串样式设计

本文通过一系列示例介绍了如何使用JavaScript操作字符串,包括计算长度、转换大小写、添加样式、创建链接等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript">
var txt = "Hello World";
//在下面的例子中,我们使用字符串对象的长度属性来计算字符串中的字符数目。
document.write(txt.length);
document.write('<br />');
//在下面的例子中,我们使用字符串对象的 toUpperCase() 方法来显示大写字母文本。
document.write(txt.toUpperCase())

//为字符串添加样式

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>Blink:(文字闪烁) " + txt.blink() + " (does not work in IE)</p>")
//以打字机文本显示字符串。
document.write("<p>Fixed: " + txt.fixed() + "</p>")
//删除线
document.write("<p>Strike: " + txt.strike() + "</p>")
//文字颜色
document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>")
//文字大小
document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>")
//把字符串转换为小写。
document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>")
//把字符串转换为大写。
document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>")
//把字符串显示为下标。
document.write("<p>Subscript: " + txt.sub() + "</p>")
//把字符串显示为上标。
document.write("<p>Superscript: " + txt.sup() + "</p>")
//将字符串显示为链接。
document.write("<p>Link: " + txt.link("http://www.w3school.com.cn") + "</p>")

</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值