W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 字符串方法</h1> <p>如果未找到文本,则 indexOf() 和 lastIndexOf() 都返回 -1:</p> <p id="demo"></p> <script> var str = "The full name of China is the People's Republic of China."; var pos = str.indexOf("USA"); document.getElementById("demo").innerHTML = pos; </script> </body> </html>