运行 ❯
获取你
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Strings</h1> <h2>The indexOf() Method</h2> <p>The indexOf() method returns the position of the first occurrence of a string in a string.</p> <p>The position of the first occurrence of "locate" is:</p> <p id="demo"></p> <script> let text = "Please locate where 'locate' occurs!"; let index = text.indexOf("locate"); document.getElementById("demo").innerHTML = index; </script> </body> </html>