字符串对象
来源:互联网 发布:樱井知香番号封面 编辑:程序博客网 时间:2024/05/22 17:27
对一直字符串进行操作
var str="Life is a foreign language;all men mispronounce it";
测试长度
str.length;
为字符串添加样式
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>")//加下划线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>")
自认为不太熟的
document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</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>")
在添加链接时 应注意添加的是URL
indexOf() 方法
如何使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置。
document.write(txt.indexOf("Life")+"<br/>");document.write(txt.indexOf("it") + "<br />")document.write(txt.indexOf("it"));
match() 方法
如何使用 match() 来查找字符串中特定的字符,并且如果找到的话,则返回这个字符。
document.write(txt.match("men")+"<br/>");document.write(txt.match("gilr"));
replace()方法
alert(txt.replace(/men/,"women"));
详情可见http://www.w3school.com.cn/jsref/jsref_obj_string.asp
阅读全文
0 0
- 字符串对象
- 字符串对象
- 使用字符串(字符串对象)
- 对象转字符串,字符串转对象
- Redis对象-1-字符串对象
- 数组对象,字符串对象,Match对象
- 自定义对象vs字符串
- javascript字符串对象
- sed字符串对象【替换】
- sed字符串对象【查找】
- 字符串对象分割【cut】
- json对象转字符串
- 对象数组转化字符串
- 拼接JSON字符串对象
- java 字符串对象
- JavaScript String(字符串)对象
- 区分 JSON 字符串 / 对象
- JavaScript 字符串(String)对象
- Linux 下安装 NVIDIA 显卡驱动
- HEXO搭建个人博客(一):发布第一篇文章
- spring @PropertySource classpath
- [PAT-乙级]1042.字符统计
- Android开发之DrawerLayout的仿QQ侧滑
- 字符串对象
- char* cp和const char *ccp的体会
- 五分钟学会Android热修复
- 南阳理工acm 91阶乘之和
- eclipse启动Tomcat服务输入http://localhost:8080/报404解决方法
- JAVA---多线程
- 使用Jsoup简单解析HTML文件示例
- C#之数据流和字符串压缩
- 理解objc_msgSend的作用