- DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>实例title>
- head>
- <body>
-
- <h1 id="myH1">h1>
- <p id="myP">p>
- <script>
- // 输出标题:
- document.getElementById("myH1").innerHTML="Welcome to my Homepage";
- // 输出段落:
- document.getElementById("myP").innerHTML="This is my first paragraph.";
- script>
- <p><b>注释:b>注释不会被执行。p>
-
- body>
- html>
- DOCTYPE html>
- <html>
- <head>
- <title>实例title>
- <meta charset="utf-8">
- head>
- <body>
-
- <h1 id="myH1">h1>
- <p id="myP">p>
- <script>
- /*
- 下面的这些代码会输出
- 一个标题和一个段落
- 并将代表主页的开始
- */
- document.getElementById("myH1").innerHTML="ngxe";
- document.getElementById("myP").innerHTML="这是一个段落。";
- script>
- <p><b>注释:b>注释块不会被执行。p>
-
- body>
- html>
实例:
- DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>实例title>
- head>
- <body>
-
- <h1 id="myH1">h1>
- <p id="myP">p>
- <script>
- //document.getElementById("myH1").innerHTML="欢迎来到我的主页";
- document.getElementById("myP").innerHTML="这是我的第一个段落。";
- script>
- <p><strong>注意:strong> 注释块不会被执行p>
-
- body>
- html>
实例:
- DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>实例title>
- head>
- <body>
-
- <h1 id="myH1">h1>
- <p id="myP">p>
- <script>
- /*
- document.getElementById("myH1").innerHTML="欢迎来到我的主页";
- document.getElementById("myP").innerHTML="这是我的第一个段落。";
- */
- script>
- <p><strong>注意:strong>注释块不会被执行。p>
-
- body>
- html>
- DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>实例title>
- head>
- <body>
-
- <p id="myP">p>
- <script>
- var x=5; // 声明 x 并把 5 赋值给它
- var y=x+2; // 声明 y 并把 x+2 赋值给它
- document.getElementById("myP").innerHTML=y // 把 y 的值写到 myP
- script>
- <p><b>注释:b>注释不会被执行。p>
-
- body>
- html>
觉得有用可以点赞或收藏!