1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 2 "http://www.w3.org/TR/xhtml1/TDT/xhtml1-strit.dtd">
 3 <html>
 4 <head>
 5 <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
 6 <title>JavaScript实例</title>
 7 <style type="text/css">
 8 
 9 </style>
10 <script type="text/javascript">
11 function displayDate()
12 {
13     document.getElementById("demo").innerHTML=Date();
14 }
15 document.write("<h1>这是一个标题</h1>");
16 document.write("<p>这是一个段落</p>")
17 
18 function maFunction()
19 {
20     x=document.getElementById("demo");//找到元素
21     x.innerHTML="Hello JavaScript!";//改变内容
22 }
23 </script>
24 </head>
25 <body>
26 <h1>我的第一个js程序</h1>
27 <p id="demo">这是一个段落</p>
28 <button type="button" onclick="displayDate()">显示日期</button>
29 <hr>
30 <!--对事件的反应-->
31 <button type="button" onclick="alert('欢迎')">点我</button>
32 <hr>
33 <!--改变元素内容-->
34 <p id="demo">JavaScript能改变HTML元素的内容</p>
35 <script>
36 function myFunction()
37 {
38     x=document.getElementById("demo");//找到元素
39     x.innerHTML="Hello JavaScript!";//改变内容
40 }
41 </script>
42 
43 <button type="button" onclick="myFunction()">点击这里</button>
44 </body>
45 </html>