W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>单击按钮,在字符串化中执行对字母“ain”(/ain)的全局(/g)搜索,并显示匹配项。</p> <button onclick="myFunction()">试一试</button> <p id="demo"></p> <script> function myFunction() { var str = "The rain in SPAIN stays mainly in the plain"; var res = str.match(/ain/g); document.getElementById("demo").innerHTML = res; } </script> </body> </html>