调试js代码输出数据,不再使用alert,使用console方法输出想要的数据。做一个高达上的程序员。Q.debugMode = false;
Q.debugIndex = 0;
Date.prototype.format = function (format) {
if (isNaN(this)) return '';
var o = {
'm+': this.getMonth() + 1,
'd+': this.getDate(),
'h+': this.getHours(),
'n+': this.getMinutes(),
's+': this.getSeconds(),
'S': this.getMilliseconds(),
'W': ["日", "一", "二", "三", "四", "五", "六"][this.getDay()],
'q+': Math.floor((this.getMonth() + 3) / 3)
};
if (format.indexOf('am/pm') >= 0) {
format = format.replace('am/pm', (o['h+'] >= 12) ? '下午' : '上午');
if (o['h+'] >= 12) o['h+'] -= 12;
}
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
}
}
return format;
}
Q.debug = function (key, value) {
if (!this.debugMode) return;
var index = (Date.prototype.format) ? (new Date()).format('hh:nn:ss.S') : (YM.debugIndex++);
if (typeof (console) == 'undefined') {
YM.debug.log(index + "--" + key + ":" + value);
} else {
if (console && console.log)
console.log(index + "--" + key, ":", value);
}
};
Q.debug.log = function () {
this.createDOM();
var p = [],
v = $('#_qdebug textarea').val();
for (var i = 0; i
p.push(arguments[i]);
}
v += (v == '' ? '' : '\n') + p.join(' ');
$('#_qdebug textarea').val(v);
};
Q.debug.clear = function () {
$('#_qdebug textarea').val('');
};
Q.debug.createDOM = function () {
if ($('#_ym_debuglog').size() == 0) {
var _html = '
$('body').append(_html);
$('#_qdebug a').click(function () {
$(this).parent().remove();
return false;
});
$('#_qdebug textarea').focus(function () {
this.select();
});
}
};
(function ($) {
if (!$) return;
$.extend(Array.prototype, {
'indexOf': function (item, it) {
for (var i = 0; i
if (item == ((it) ? this[i][it] : this[i])) return i;
}
return -1;
},
'remove': function (item, it) {
this.removeAt(this.indexOf(item, it));
},
'removeAt': function (idx) {
if (idx >= 0 && idx
for (var i = idx; i
this[i] = this[i + 1];
}
this.length--;
}
},
'removeEmpty': function () {
var arr = [];
for (var i = 0; i
if (this[i].trim() != '') {
arr.push(this[i].trim());
}
}
return arr;
},
'add': function (item) {
if (this.indexOf(item) > -1) {
return false;
} else {
this.push(item);
return true;
}
},
'swap': function (i, j) {
if (i
var item = this[i];
this[i] = this[j];
this[j] = item;
}
},
'filter': function (it, item) {
var arr = [];
for (var i = 0; i
if (typeof (item) == 'undefined') {
arr.push(this[i][it]);
} else if (this[i][it] == item) {
arr.push(this[i]);
}
}
return arr;
},
'unique': function () {
var a = [],
o = {},
i, v, len = this.length;
if (len
for (i = 0; i
v = this[i];
if (o[v] !== 1) {
a.push(v);
o[v] = 1;
}
}
return a;
},
'sortby': function (it, dt, od) {
var compareValues = function (v1, v2, dt, od) {
if (dt == 'int') {
v1 = parseInt(v1);
v2 = parseInt(v2);
} else if (dt == 'float') {
v1 = parseFloat(v1);
v2 = parseFloat(v2);
}
var ret = 0;
if (v1
if (v1 > v2) ret = -1;
if (od == 'desc') {
ret = 0 - ret;
}
return ret;
};
var newdata = new Array();
for (var i = 0; i
newdata[newdata.length] = this[i];
}
for (var i = 0; i
var minIdx = i;
var minData = (it != '') ? newdata[i][it] : newdata[i];
for (var j = i + 1; j
var tmpData = (it != '') ? newdata[j][it] : newdata[j];
var cmp = compareValues(minData, tmpData, dt, od);
if (cmp
minIdx = j;
minData = tmpData;
}
}
if (minIdx > i) {
var _child = newdata[minIdx];
newdata[minIdx] = newdata[i];
newdata[i] = _child;
}
}
return newdata;
}
});
})(jQuery);
打赏支付宝打赏
微信打赏