虽然不是很复杂的实现,但每次都要这样就会很麻烦,所以我写了一小段脚本,用来自动生成这个输出窗口。
代码
复制代码 代码如下:
window.Babu = {};
Babu.Debugging = {};
Babu.Debugging.writeLine = function(format, arg1, arg2) {
var console = Babu.Debugging._getConsole();
if (console.get_visible()) {
var msg = format;
if (typeof msg !== "undefined" && msg !== null) {
var index;
if (typeof msg === "string") {
var array = format.match(/\{(\d+)\}/g);
if (array) {
for (var i = 0; i < array.length; i++) {
index = array[i];
index = parseInt(index.substr(1, index.length - 2)) + 1;
msg = msg.replace(array[i], arguments[index]);
}
}
}
}
var span = document.createElement("SPAN");
span.appendChild(document.createTextNode(msg));
console._output.appendChild(span);
console._output.appendChild(document.createElement("BR"));
span.scrollIntoView();
return span;
}
}
Babu.Debugging._getConsole = function() {
var console = Babu.Debugging._console;
if (!console) {
var div = document.createElement("DIV");
div.style.position = "fixed";
div.style.right = "3px";
div.style.bottom = "3px";
div.style.width = "350px";
div.style.height = "180px";
div.style.backgroundColor = "white";
div.style.color = "black";
div.style.border = "solid 2px #afafaf";
div.style.fontSize = "12px";
document.body.appendChild(div);
Babu.Debugging._console = console = div;
div = document.createElement("DIV");
div.style.backgroundColor = "#e0e0e0";
div.style.position = "absolute";
div.style.left = "0px";
div.style.right = "0px";
div.style.top = "0px";
div.style.height = "16px";
div.style.padding = "2px 2px";
div.style.margin = "0px";
console.appendChild(div);
console._toolbar = div;
div = document.createElement("DIV");
div.style.overflow = "auto";
div.style.whiteSpace = "nowrap";
div.style.position = "absolute";
div.style.left = "0px";
div.style.right = "0px";
div.style.top = "20px";
div.style.bottom = "0px";
div.style.height = "auto";
console.appendChild(div);
console._output = div;
var btn;
btn = document.createElement("SPAN");
btn.innerHTML = "收缩";
btn.style.margin = "0px 3px";
btn.style.cursor = "pointer";
console._toolbar.appendChild(btn);
btn.onclick = function() { if (console.get_collapsed()) console.expand(); else console.collapse(); }
btn = document.createElement("SPAN");
btn.innerHTML = "清除";
btn.style.margin = "0px 3px";
btn.style.cursor = "pointer";
console._toolbar.appendChild(btn);
btn.onclick = Babu.Debugging.clearConsole;
btn = document.createElement("SPAN");
btn.innerHTML = "关闭";
btn.style.cursor = "pointer";
btn.style.margin = "0px 3px";
console._toolbar.appendChild(btn);
btn.onclick = function() { Babu.Debugging.hideConsole(); }
console.get_visible = function() { return this.style.display !== "none" };
console.get_collapsed = function() { return !(!this._collapseState) };
console.collapse = function() {
if (!this.get_collapsed()) {
this._output.style.display = "none";
this._toolbar.childNodes[1].style.display = "none";
this._toolbar.childNodes[2].style.display = "none";
this._toolbar.childNodes[0].innerHTML = "展开";
this._collapseState = { width: this.style.width, height: this.style.height }
this.style.width = "30px";
this.style.height = "16px";
}
}
console.expand = function() {
if (this.get_collapsed()) {
this._output.style.display = "";
this._toolbar.childNodes[1].style.display = "";
this._toolbar.childNodes[2].style.display = "";
this._toolbar.childNodes[0].innerHTML = "收缩";
this.style.width = this._collapseState.width;
this.style.height = this._collapseState.height;
this._collapseState = null;
}
}
}
return console;
}
Babu.Debugging.showConsole = function() {
Babu.Debugging._getConsole().style.display = "";
}
Babu.Debugging.hideConsole = function() {
var console = Babu.Debugging._console;
if (console) {
console.style.display = "none";
}
}
Babu.Debugging.clearConsole = function() {
var console = Babu.Debugging._console;
if (console) console._output.innerHTML = "";
}
调用方法很简单:
复制代码 代码如下:
Babu.Debugging.writeLine("调试信息");
Babu.Debugging.writeLine("带参数的调试信息:参数1={0},参数2={1}", arg1, arg2);
调用之后,会自动在窗口的右下角出现一个固定位置的窗口,并显示相应的内容。效果图请看下面:
相关推荐:
SEO指:如何通过精准优化提高网站流量和转化率,无锡论坛营销推广要多久
seo独立站是什么,独立站推广是什么 ,ai曲线笔刷扩展
AI一键生成文章,写作新境界
SEO优化做什么的?揭秘SEO优化的核心价值与实战应用,ai做金色
为什么说seo这么重要,seo重要吗 ,ai19920403
SEO有话:如何用精准优化助力企业在线增长,食品微信营销推广
seo追词是什么,seo词条 ,52580609AI
ChatGPT无法访问原因分析及解决方案,斑马ai报道
WPS改写-轻松提升文档创作效率的秘密武器,推广网站的优势
SEO赚钱:如何通过SEO技能在网络上实现财富自由,网站怎么建设推广平台
SEO建议:如何通过优化提升网站流量,赢得市场竞争,自媒体网站免费推广平台
如何通过AI写文章,轻松提高写作效率与质量
seo资源是什么意思,seo资源怎么打开 ,梅州ai自动插件加工
seo都有什么意思,seo 啥意思 ,ai园林
ChatGPT坏了用什么?替代方案,满足你的智能对话需求,星际一的ai
为什么seo这么麻烦,seo是什么意思 为什么要做seo ,dota1ai地图命令选ai
SEO总计:如何通过SEO优化实现网站流量和排名的飞跃,三元桥网站优化
为什么越来越多的人选择在知乎发布文章?这里面的机会你可能还没发现!,潍坊关键词排名提升
seo需要学习什么语言,做seo需要懂什么技术 ,ai软件制作教程
AI优化文章:如何利用人工智能提升写作效率和质量
SEO如何做?全方位解析提升网站排名的秘诀,AI翻译好处
SEO汇报:如何通过数据分析提升网站排名,助力企业业绩增长,免费推广网站大全百度经验
高效创作新时代AI文案速写工具,让创作更轻松
AI一键生成文章网页版,让内容创作更简单高效
seo高手有什么条件,seo难上手吗 ,指南ai写作电力创新
ChatGPT为什么打不开了?揭秘背后的原因与解决办法,ai业务后端
360关键:打造全方位安全保护,守护您的数字世界,ai乘bi
SEO和品牌营销:如何通过搜索引擎优化打造品牌影响力,建邺seo软件
怎么识别是AI写的文章
seo要什么条件,seo都需要做什么 ,交互ai求职
优排软件:高效管理新天地,轻松提升工作效率,长葛外贸网站建设
seo用什么论坛引流,seo引流方法 ,ai写作续写神器
ChatGPT登录503错误?轻松解决,快速恢复畅享智能体验!,ai怎么加植物材质效果
ChatGPT免费版每天提问有次数限制吗?揭秘如何高效使用AI助手!,机甲ai手绘
ChatGPT破解版电脑:如何获得更强大的AI助手,提升工作与学习效率,ai预设动画
wordpress seo是什么,wordpress建站seo好做吗 ,学习图文ai
SEO搜外:全球搜索引擎优化的秘密武器,如何选择网站建设类型呢
互联网资源的无限潜力:如何利用数字世界为个人和企业创造价值,信阳网站建设正规公司
SEO出超:如何通过精准优化实现网站流量大爆发,营销推广方式联系f火15星
SEO包含的秘密:让你的网站轻松排上首页,新媒体营销推广方案目录
SEO选择:如何挑选最合适的SEO优化策略?,wb免费刷粉网站推广
“收录量为1”,打造数字化时代的独特竞争力,网站建设页面制作流程
ChatGPT为什么页面下拉不了?问题解析与解决方案,ai对准
SEO教研:数字营销新趋势,提升网站流量与转化率的关键,齐鲁证券网站建设
企业营销:如何在竞争激烈的市场中脱颖而出,美装网站Seo优化
OpenAI智能诊断医疗-开启精准医疗新纪元,跟侯维静学ai
seo简报什么意思,seo工作汇报 ,万花筒 ai
SEO网:让你的数字营销更加精准高效,开启网络引流新时代,丰县互联网网站推广优势
ChatGPT:人工智能对话新时代的领航者,ai音响华为还是小米好
seo需要什么能力,seo需要哪些技术 ,ai长条弯曲