javascript - 为什么这个 console.log() 函数不起作用?
问题描述
<!DOCTYPE html>
<html>
<head>
<title>LearnJS</title>
</head>
<body>
<script>
console.log('hello World\nThis is me');
alert("This is an \nalert.");
</script>
</body>
</html>
我已经尝试过这段代码并在 TORCH borwser 中运行...显示的唯一输出是 alert 但它不显示 console.log 的输出...可能的解决方案是什么...我用过
document.write('hello World\nThis is me');
但是这段代码没有换行所以我应该使用console.log ...
解决方案
它在这里工作正常:)。运行代码片段
<!DOCTYPE html>
<html>
<head>
<title>LearnJS</title>
</head>
<body>
<script>
console.log('hello World\nThis is me on console');
alert("This is an \nalert.");
document.write("This is an document.write.");
</script>
</body>
</html>
笔记:
- 开发人员
console.log()
用于在浏览器控制台上记录有用信息 document.write()
通过向 DOM 添加其他内容来修改用户在浏览器中看到的内容。alert()
's 用于提醒在浏览器上访问网页的最终用户。
注意如果您对 stackoverflow.com 如何console.log()
在浏览器 div 上显示感到困惑。然后在这里查看https://stackoverflow.com/a/20256785/1138192它有点覆盖console.log()
在浏览器 div 上显示消息的默认行为。希望这可以帮助 :)
推荐阅读
- ios - 为什么在 iPhone 模拟器上单击按钮时没有音符声音?
- node.js - 浏览器下载文件而不是显示 html
- php - 无法从 Laravel 应用程序连接到 Azure MySQL
- jquery - datepicker 和 jsp,获取价值的问题
- c - 使用 realloc 将 CSV 文件保存在数组中
- generics - 如何将 F# 联合类型的使用限制为特定选项
- opencv - OpenCV 相机校准和 SolvePNP 转换结果
- regex - 拆分正则表达式,只返回字符、数字和下划线。Perl
- php - MySQL:过滤结果的查询
- django - 使用Django中的related_name属性访问父模型中的子模型实例