源代码
<!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("享学课堂","www.2xkt.com"); document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
运行结果