zoukankan      html  css  js  c++  java
  • javascript语法之String对象

    学习String类就是学习它的一些方法,主要用到方法全部罗列出来。如下:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script type="text/javascript"> 
     
    /*
    	var str1 = new String("hello");
    	var str2 = new String("hello");
    	document.write("两个字符串的对象一样吗?"+(str1.toString()==str2.toString()));
     
    创建一个字符串的方式:
    方式1:
    	new String("字符串的内容");
    	
    方式2:
    	var str = "字符串的内容";
     
     
     
    字符串常用的方法:
    	anchor()   生产锚点
    	blink()     为元素添加blink标签 
    	charAt()     返回指定索引位置处的字符。
    	charCodeAt() 回一个整数,代表指定位置上字符的 Unicode 编码。
    	
    	
    	fontcolor()  把带有 COLOR 属性的一个 HTML <FONT> 标记放置在 String 对象中的文本两端
    	
    	indexOf()    返回 String 对象内第一次出现子字符串的字符位置
    	
    	
    	italics()    把 HTML <I> 标记放置在 String 对象中的文本两端。 
    	
    	link()         把一个有 HREF 属性的 HTML 锚点放置在 String 对象中的文本两端。
    	
    	replace()      返回根据正则表达式进行文字替换后的字符串的复制
    	
    	split()        切割   
    	
    	Substr()       截取子串
    	toUpperCase()  转大写
    	toLowerCase    转小写
    */
    	document.write("第五章".anchor("five")+"<br/>");
    	document.write("第五章".blink()+"<br/>");
    	document.write("abc".charAt(1)+"<br/>");
    	document.write("abc".charCodeAt(1)+"<br/>"); //chatCodeAt返回的是索引值对应的字符的码值。 
    	document.write("第六章".fontcolor("red")+"<br/>"); //fontcolor() 给字符串添加font标签,然后设置color的属性值。
    	document.write("abchellohehehello".indexOf("hello")+"<br/>"); //返回指定字符串第一次出现的索引值。
    	document.write("第五章".italics()+"<br/>"); //给文本添加一个i标签,把文本内容设置成斜体。
    	document.write("哈哈".link("http://www.itcast.cn")+"<br/>"); // 给文本添加一个a标签,
    	document.write("明天学习xml".replace("xml","DOM编程")+"<br/>"); // 替换
    	
    	var str = "我们-大家-好";
    	var arr = str.split("-");
    	for(var index = 0 ; index<arr.length ; index++){
    		document.write(arr[index]+",");	
    	}
    	document.write("<br/>");
    	document.write("abc".toUpperCase()+"<br/>"); //转大写
    	document.write("ABC".toLowerCase()+"<br/>");  //转小写
    	
    	
    	
    	
    	
    	
     
    	
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
     
    <body>
    </body>
    </html>
    


  • 相关阅读:
    html5+css3中的background: -moz-linear-gradient 用法 (转载)
    CentOS 安装Apache服务
    Linux 笔记
    CURL 笔记
    Spring Application Context文件没有提示功能解决方法
    LeetCode 389. Find the Difference
    LeetCode 104. Maximum Depth of Binary Tree
    LeetCode 520. Detect Capital
    LeetCode 448. Find All Numbers Disappeared in an Array
    LeetCode 136. Single Number
  • 原文地址:https://www.cnblogs.com/wanghang/p/6299785.html
Copyright © 2011-2022 走看看