WEB前端浏览器控制台基本使⽤技巧
输⼊代码前使⽤快捷键换⾏ shift+enter
弹窗
alert
打印
console.log("打印的信息");
输出调试信息
console.debug("调试的信息");
输出提⽰性信息
console.info("提⽰的信息");
输出错误信息
<("错误的信息");
输出警⽰信息
console.warn("警⽰的信息");
输出⼀组信息
⽤于查看页⾯中某个节点的 html/xml 代码。
var div = ElementById("div");
console.dirxml(div);
console.log(div);
清空控制台历史记录
clear()
断⾔
console.assert(length < 500, "Node length is > 500");
过滤输出
你可以根据级别对⽇志输出进⾏过滤
All - 显⽰所有的输出
Errors - 只显⽰ () 的输出
Warnings - 只显⽰ console.warn()的输出
Info - 只显⽰ console.info()的输出
Logs - 只显⽰ console.log()的输出
Debug - 只显⽰ console.timeEnd() 和 console.debug()的输出
字符串裁剪和格式化
⽇志输出⼀系列⽅法的第⼀个字符串参数都可以包含⼀个或者多个格式符。格式符由%后⾯跟⼀个字母组成,字母代表不同的格式。每个格式符与后⾯的参数⼀⼀对应。
下⾯的例⼦中,⽇志打印了结果中包含了字符串格式和数字格式内容。
console.log("%s has %d points", "Sam", 100);
The full list of format specifiers are as follows:
%s - 字符串格式
%i 或 %d - 整型格式
%f - 浮点格式
%o - DOM节点
%O - JavaScript 对象
%c - 对输出的字符串使⽤css样式,样式由第⼆个参数指定。
下⾯的例⼦使⽤整型来打印 document.childNodes.length的值,使⽤浮点格式来打印w()的值。
console.log("Node count: %d, and the time is %f.", document.childNodes.length, w());
jsessionidPOST请求
var url = "127.0.0.1:8088/test";
var params = {token:"JSESSIONID=FD4518A98B70344129B233FF3701654F;",page:"1"};
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
if (adyState === 4) {
if (xhr.status === 200) {
console.sponseText);
} else {
<(xhr.statusText);
}
}
};
<(xhr.statusText);
};
xhr.send(JSON.stringify(params));
GET请求
var url = "127.0.0.1:8088/test?types=userType,userStatus"; var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
if (adyState === 4) {
if (xhr.status === 200) {
console.sponseText);
} else {
<(xhr.statusText);
}
}
};
<(xhr.statusText);
};
xhr.send(null);

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。