人生具有无限的可能性,你的梦想一定能实现

JS重新来过之------------[String对象]

indexof()方法的使用

该方法用来定位某一个字符在字符串中的位置,如果找不到则返回值 “-1”,否则,返回位置,从0开始计算;

二、使用match()方法

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

<html>
	<head>
		<title>match()方法</title>
		<script type="text/javascript">
			var str="Do you have feeling?";
			document.write(str.match("you")+"</br>");
			document.write(str.match("You")+"</br>");
			document.write(str.match("your")+"</br>");
		</script>
	</head>

	<body>
	</body>
</html

返回值:

三、repleace()替换字符串中的字符

  replace() 方法在字符串中用某些字符替换另一些字符。

<html>
	<body>
	<script type="text/javascript">

	var str="hello world!";
	document.write(str.replace(/world/,"boy"));
	document.write("\n"+str+"\n");
	document.write(str.replace("world","girl"));

	</script>
	</body>
</html>

返回值:

posted @ 2011-05-26 16:40  代号极光  阅读(250)  评论(0编辑  收藏  举报

本博客所有权归作者代号极光紫竹园博客园