今天我们继续根据w3c的官方网站学习javascript的内容。以下代码均可复制直接执行。
![](https://img.haomeiwen.com/i12601884/db10173dbb084278.png)
显示输入结果,其他所的html标签全部删除
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h2>my first web app </h2>
<p>this is my studay web page</p>
<button type="button" onclick="document.write(5+6)"> try it</button>
</body>
</html>
执行输入的结果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h2>my input conten</h2>
<p>my first parag</p>
<script>
document.write (100+200)
</script>
</body>
</html>
显示弹窗
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>my first web page!</h1>
<p>this is my second page!</p>
<script>window.alert("页面加载成功,恭喜你!")</script>
</body>
</html>
效果图
![](https://img.haomeiwen.com/i12601884/cac2e6a2c03172e3.png)
输出控制台信息
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>console.log("hao are you !")</script>
</body>
</html>
总结:
今天我们学习了javascript的输出的基本操作,下一篇文章我们来练习变量声明的操作。
网友评论