2018.11.11更新:可以直接使用微信的vconsole库
https://github.com/Tencent/vConsole
手机上根本看不到控制台,那如何查看打印的信息呢?
可以使用下面的方法去实现打印
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<textarea id="id-text-log" name="name" rows="20" cols="50"></textarea>
</body>
<script type="text/javascript">
var e = sel => document.querySelector(sel)
// var log = console.log.bind(console)
var log = function() {
var result = ''
// console.log(arguments)
var args = Array.prototype.slice.call(arguments);
args.forEach(function(value){
// console.log(value)
if(typeof value == 'object') {
value = JSON.stringify(value)
}
result += value + ' '
});
console.log(result)
e('#id-text-log').value += result + '\n'
}
log(1, 2, 3, 4)
log({1: 2}, 12)
log([1, 2, 3, 4])
</script>
</html>
效果图如下:
![](https://img.haomeiwen.com/i6921018/3a3f1f3d5b574c5e.png)
网友评论