提示和注释

注释:indexOf() 方法对大小写敏感!

注释:如果要检索的字符串值没有出现,则该方法返回 -1。找到了返回出现的位置数字

实例

在本例中,我们将在 "Hello world!" 字符串内进行不同的检索:

<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>

以上代码的输出:

0    出现的位置是0
-1  没有找到该字符串
6   出现的位置第6个位置

相关文章:

  • 2021-08-09
  • 2021-07-15
  • 2021-10-02
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-16
猜你喜欢
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案