js 希碎的知识点 第二次

本文介绍JavaScript中字符串的各种内置样式方法,包括大小写转换、字体颜色设置等,并探讨如何使用indexOf()和lastIndexOf()定位字符位置。

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


一 、 面向对象的javascript

     对象:只是一种特殊的数据。对象拥有属性和方法。

  (1) 字符串的内置方法

            给字符串加样式的方法

<html>
<body>

<script type="text/javascript">

var txt="Hello World!"

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>")   照片:  Hello World!

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>

</body>
</html>


   (2)  indexOf() 来定位字符串中某一个指定的字符首次出现的位置;

               lastIndexOf() 从后向前检索。

    (3)如何使用 match() 来查找字符串中特定的字符,并且如果找到的话,则返回这个字符;

   (4) txt.slice(start,end)  提取字符串指定位置的字符



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值