JavaScript------字符串中各种方法

参考“菜鸟教程”

http://www.runoob.com/js/js-strings.html

 

1.search()
var s = "Hello World";
alert(s.search(/World/i)); //输出6
//相当于
alert(s.search("World"));

 

2.replace()
var s = "Hello World";
alert(s.replace(/World/i,"China")); 
//相当于
alert(s.replace("World","China"));

 

posted @ 2017-01-13 13:59  玉天恒  阅读(128)  评论(0)    收藏  举报