确定文本在字符串中首次出现的位置 - indexOf()
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 字符串方法</h1>
- <p>indexOf() 方法返回指定文本首次出现的位置:</p>
- <p id="demo"></p>
- <script>
- var str = "The full name of China is the People's Republic of China.";
- var pos = str.indexOf("China");
- document.getElementById("demo").innerHTML = pos;
- </script>
- </body>
- </html>