js调试的时候怎么在console中输出信息

 我来答
金色潜鸟
2017-03-27 · TA获得超过3.2万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:5492万
展开全部
用函数 console.log(...)
函数原型是:
console.log(obj1 [, obj2, ..., objN]);
console.log(msg [, subst1, ..., substN]);
例子:
<html><body>
<h2>Activate debugging with F12</h2>
<p>Select "Console" in the debugger menu. Then click Run again.</p>
<script>
console.log(5 + 6);
</script>
</body></html>
按F12键,起动debug,选Console,点Run 就见输出。
--
语句例子:var car = "Dodge Charger";
var someObject = {str:"Some text", id:5};
console.info("My first car was a", car, ". The object is: ", someObject);
输出内容: My first car was a Dodge Charger . The object is: ({str:"Some text", id:5}
循环语句输出例子:for (var i=0; i<5; i++) {
console.log("Hello, %s. You've called me %d times.", "Bob", i+1);
}
输出有颜色的字体例子:
console.log("This is %cMy stylish message", "color: yellow; font-style: italic; background-color: blue;padding: 2px");
海甸岛的骄傲
2017-03-27 · TA获得超过820个赞
知道小有建树答主
回答量:147
采纳率:100%
帮助的人:131万
展开全部

使用console对象中的log方法,可以在控制台中输出。

在浏览器中按F12,打开开发人员工具,切换到到console选项卡即可看到输出的信息。

举例:

var x = {a:1, b:2};
console.log(s);
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式