x=y+2;
---------------------------------------
++++++++++++++++++++
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
var pi = 3.14;
var name = "Bill Gates!";
var answer = 'Yes i am';
document.write(pi + "<br>");
document.write(name + "<br>");
document.write(answer + "<br>");
</script>
</body>
</html>
---------------------------------------
++++++++++++++++++++
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html charset = utf-8"/>
<head>
<title></title>
</head>
<body>
<p>点击这里创建变量,并显示结果</p>
<p id = "demo"></p>
<script type="text/javascript">
function myfunction()
{
var name="Bill Gates";
document.getElementById("demo").innerHTML=name;
}
</script>
<button type="button" onclick="myfunction()">点击这里</button>
</body>
</html>
---------------------------------------
++++++++++++++++++++
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html charset = utf-8"/>
<head>
<title></title>
</head>
<body>
<p id = "demo"></p>
<p id = "Angel"></p>
<h1>假设 y=5,计算 x=y+2,并显示结果</h1>
<button onclick="myfunction()">点击开始</button>
<button onclick="function_name()">点击测试</button>
<script type="text/javascript">
function myfunction()
{
var y = 5;
var x = y + 2;
var demoP = document.getElementById("demo");
demoP.innerHTML="x="+x;
}
function function_name ()
{
var carname = "Bill Gates";
document.getElementById("Angel").innerHTML=carname;
}
</script>
</body>
</html>
---------------------------------------
++++++++++++++++++++
<!DOCTYPE html>