源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-String对象
来源:互联网 发布:深蓝知乎 编辑:程序博客网 时间:2024/06/05 15:39
属性:length
方法:
toUpperCase(), toLowerCase(), charAt(), indexOf(), lastIndexOf(), substring(), split(), trim(), replace()
示例效果:
JS代码:
// Create a variable called saying to hold the string that will be usedvar saying = 'Home sweet home ';// Create a variable called msg to hold a message that will be shown on the page// Find the length of the string, and put this in the msg variablevar msg = '<h2>length</h2><p>' + saying.length + '</p>';// Convert the string to uppercase and add it to the msg variablemsg += '<h2>uppercase</h2><p>' + saying.toUpperCase() + '</p>';// Convert the string to lowercase and add it to the msg variablemsg += '<h2>lowercase</h2><p>' + saying.toLowerCase() + '</p>';// Find the character with an index of 12 in the string and add it to the msg variablemsg += '<h2>character index: 12</h2><p>' + saying.charAt(12) + '</p>';// Find the index number of the first instance of 'ee' in the string and add it to the msg variablemsg += '<h2>first ee</h2><p>' + saying.indexOf('ee') + '</p>';// Find the index number of the last instance of the 'e' character in the string and add it to the msg variablemsg += '<h2>last e</h2><p>' + saying.lastIndexOf('e') + '</p>';// Find the characters with an index number in the 8-14 range in the string and add it to the msg variablemsg += '<h2>character index: 8-14</h2><p>' + saying.substring(8, 14) + '</p>';// Find the first instance of 'me' in the string and replace it with a 'w' character and add it to the msg variablemsg += '<h2>replace</h2><p>' + saying.replace('me', 'w') + '</p>';// Create a variable called el to hold the element whose id attribute has a value of infovar el = document.getElementById('info');// Write the message into that elementel.innerHTML = msg;
HTML代码:
<!DOCTYPE html><html> <head> <title>JavaScript & jQuery - Chapter 3: Functions, Methods & Objects - String Object</title> <link rel="stylesheet" href="css/c03.css" /> </head> <body> <h1>TravelWorthy</h1> <div id="info"></div> <script src="js/string-object.js"></script> </body></html>
CSS代码:(参考源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-使用字面量语法创建对象,http://blog.csdn.net/hpdlzu80100/article/details/52677426 )
0 0
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-String对象
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-浏览器对象模型
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-文档对象模型
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-章节示例
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-使用构造函数语法创建对象
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-使用字面量语法创建对象
- 源码-JavaScript&jQuery交互式前端开发-第5章-文档对象模型-更新文本和标签
- 源码-JavaScript&jQuery交互式前端开发-第5章-文档对象模型-章节示例
- 源码-JavaScript&jQuery交互式前端开发-第7章-JQuery-基本示例
- 源码-JavaScript&jQuery交互式前端开发-第7章-JQuery-修改内容
- 源码-JavaScript&jQuery交互式前端开发-第2章-JavaScript基础指令-章节示例
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-鼠标事件-浮层的显示与关闭
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-Focus和blur事件
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-鼠标事件-确定光标位置
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-键盘事件-确定按键值
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-表单事件
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-变动事件
- 源码-JavaScript&jQuery交互式前端开发-第6章-事件-HTML5事件
- Ubuntu12.04 在右键快捷菜单中添加“Open in Terminal”
- 【C++】谈一谈this指针
- Mybatis简介与原理
- 从尾到头打印链表
- UVa OJ 1625 - Color Length
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-String对象
- Android开发架构规范
- 突破CND的一些方法
- 常用的实用工具jar包导入
- 分布式定时任务框架-Elastic Job
- DataCenter 数据中心
- 死锁
- 72. Edit Distance
- 226. Invert Binary Tree