-
Notifications
You must be signed in to change notification settings - Fork 3
/
0613-06.字符串对象.html
33 lines (33 loc) · 1.22 KB
/
0613-06.字符串对象.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var commet="静夜思李白窗前明月光,疑是地上霜,举头望明月,低头思故乡.";
var partial=commet.substring( 0,3 );
//string.substring(start,stop)
//start必须要有,规定需要提取的字符串第一个字符在string中的位置
//stop可选,一个非负数,比提取的字符串最后一个字符多1,如果省略这个参数,返回字符串一直到结尾
//document.write(partial);
partial=partial.bold() //标题加粗
document.write("<p align=\"center\" >") //设置居中
document.write(partial);
partial=commet.slice(3,5);
//slice用法:arrayObject.slice(start,end)
//返回一个新的数组,包含start到end(不包含该元素)的arryobject中元素
document.write("<br>");
document.write(partial);
partial=commet.slice(5,17);
partial=partial.fontcolor("skyblue"); //字体颜色设置天空蓝
document.write("<br>");
document.write(partial);
partial=commet.slice( 17,29);
partial=partial.fontcolor("pink"); //字体颜色设置少女粉
document.write("<br>");
document.write(partial);
document.write("</p>");
</script>
</body>
</html>