首先,在Html页面输出,使用document.write('内容');

<html> <head> <title></title> <script> document.write("头部的:第一次javascript测试!"); </script> </head> <body> <p/> <script> document.write("第一次javascript测试!"); </script> <p>第一次javascript测试!</p> </body> </html>
注意事项:

1 <html> 2 <body> 3 4 <h1>My First Web Page</h1> 5 6 <p>My First Paragraph.</p> 7 8 <button onclick="myFunction()">点击这里</button> 9 10 <script> 11 function myFunction() 12 { 13 document.write("糟糕!文档消失了。"); 14 } 15 </script> 16 17 </body> 18 </html>
javascript对事件作出的处理,onclick="";

1 <html> 2 <body> 3 <h1>JavaScript</h1> 4 <p> 5 JavaScript 能够对事件作出反应。比如对按钮的点击: 6 </p> 7 <button type="button" onclick="alert('Welcome!')">点击这里</button> 8 </body> 9 </html>
<html>
<body>
<p id="demo">
JavaScript 能改变 HTML 元素的内容。
</p>
<script>
function myFunction()
{
x=document.getElementById("demo"); // 找到元素
x.innerHTML="Hello JavaScript!"; // 改变内容
}
</script>
<button type="button" onclick="myFunction()">点击这里</button>
</body>
</html>