源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>在下面的段落中搜索 "e":</p> <p id="p01">The best things in life are free!</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> function myFunction() { text = document.getElementById("p01").innerHTML; document.getElementById("demo").innerHTML = /e/.test(text); } </script> </body> </html>
运行结果