<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>我的网页</h1> <p id="demo">我的第一个段落。</p> <script> document.getElementById("demo").innerHTML = "你好 Dolly"; </script> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>我的网页</h1> <p id="demo1"></p> <p id="demo2"></p> <script> a = 1; b = 2; c = a + b; document.getElementById("demo1").innerHTML = c; x = 1; y = 2; z = x + y; document.getElementById("demo2").innerHTML = z; </script> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>我的 Web 页面</h1> <p id="demo">一个段落。</p> <div id="myDIV">一个 DIV。</div> <script> document.getElementById("demo").innerHTML="你好 Dolly"; document.getElementById("myDIV").innerHTML="你最近怎么样?"; </script> </body> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <h1>我的 Web 页面</h1> <p id="myPar">我是一个段落。</p> <div id="myDiv">我是一个div。</div> <p> <button type="button" onclick="myFunction()">点击这里</button> </p> <script> function myFunction(){ document.getElementById("myPar").innerHTML="你好世界!"; document.getElementById("myDiv").innerHTML="你最近怎么样?"; } </script> <p>当您点击上面的按钮时,两个元素会改变。</p> </body> </html>