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