js调试的时候怎么在console中输出信息
发布网友
发布时间:2023-11-29 22:36
我来回答
共2个回答
热心网友
时间:2024-12-02 09:58
用函数 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");
热心网友
时间:2024-12-02 09:59
使用console对象中的log方法,可以在控制台中输出。
在浏览器中按F12,打开开发人员工具,切换到到console选项卡即可看到输出的信息。
举例:
var x = {a:1, b:2};
console.log(s);