源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>替换所有"享学课堂"用"www.2xkt.com":</p> <button onclick="myFunction()">试试</button> <p id="demo">请访问享学课堂和享学课堂!</p> <script> function myFunction() { var str = document.getElementById("demo").innerHTML; var txt = str.replace(/享学课堂/g,"www.2xkt.com"); document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
运行结果