Javascript初级学习总结

  首先,在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>
javascript在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输出调用区别

  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>

原文地址:https://www.cnblogs.com/SoftShine/p/3727866.html