如何在 JavaScript 中显示输出?
可以在 JavaScript 中以 4 种方式显示输出。
a) 使用 innerHTML 属性在 HTML 元素中显示输出。
示例
<html>
<body>
<p id="display"></p>
<script>
document.getElementById("display").innerHTML = 10 + 10;
</script>
</body>
</html>输出
20.
b) 使用 document.write() 显示输出。
示例
<html> <body> <script> document.write(2 + 3); </script> </body> </html>
输出
5
c) 通过 console.log() 显示输出。
示例
<html> <body> <script> console.log(2 + 3); </script> </body> </html>
在调试器控制台中,输出
5.
d) 通过警报框显示输出。
示例
<html> <body> <script> alert(2 + 3); </script> </body> </html>
在警报窗口框中,输出
5
如果要处理 JSON 字符串或其他一些大数据,那么 console.log 是最佳选择。
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP