您的当前位置:首页正文

js中字符串位置的搜索方法

来源:华拓网

1、indexof方法从字符串开始向后搜索子字符串。

2、lastIndexof方法是从字符串末尾搜索子字符串。

3、trim将创建一个字符串副本,删除前置和后缀的所有空格,然后返回结果。

实例

<script type="text/javascript">    
var str="Hello world!";  
document.write(str.indexOf("Hello") + "<br />");  
document.write(str.indexOf("World") + "<br />");
document.write(str.indexOf("world"));    
</script>

以上就是js中字符串位置的搜索方法,希望对大家有所帮助。更多js学习指路: