源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>搜索 "享学课堂", 显示匹配的位置:</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> function myFunction() { var str = "访问享学课堂!"; var n = str.search(/享学课堂/i); document.getElementById("demo").innerHTML = n; } </script> </body> </html>
运行结果