-2
所以我想通過在它的不同部分應用console.log來測試我的代碼。但是當我在某個功能中嘗試它時,它不起作用。我已經嘗試在該函數中放入警報,以查看它是否僅僅是console.log的問題,但警報似乎也不運行。Console.log不能在我的函數內工作
這裏是我的代碼
var mqrule;
var lines;
var width;
console.log("Nothing");
//HASHMAP BEGINNING HERE
var newKey, newValue;
var MQHash = {};
MQHash[newKey] = newValue;
(function() {
console.log("Nothing");
//FROM HERE, CONSOLE.LOG DOESN'T SEEM TO BE WORKING.
var mqEvents = function (mediaChangeHandler) {
var sheets = document.styleSheets,
numSheets = sheets.length,
mqls = {},
mediaChange = function (mql) {
console.log(mql);
}
if (mediaChangeHandler) {
mediaChange = mediaChangeHandler;
}
for (var i = 0; i < numSheets; i += 1) {
var rules = sheets[i].cssRules,
numRules = rules.length;
console.log("RULES: " + rules);
for (var j = 0; j < numRules; j += 1) {
if (rules[j].constructor === CSSMediaRule) {
mqrule = rules[j].cssText;
console.log(mqrule);
lines = (mqrule).split('\n');
console.log(lines[1]);
mqls['mql' + j] = window.matchMedia(rules[j].media.mediaText);
mqls['mql' + j].addListener(mediaChange);
mediaChange(mqls['mql' + j]);
}
}
}
}
//IT STARTS TO WORK AGAIN FROM HERE THOUGH.
window.mqEvents = mqEvents;
}());
handleMediaChange = function (mql) {
console.log();
var medias = mql.media;
}
有什麼建議?提前致謝。對不起,如果這個問題措辭不當!
_alerts似乎無法運行_清楚地表明問題在別的地方。 – Satpal
你在哪裏打電話給mqEvents? –
警報在該部分之外運行,但不在該部分之內。真的很抱歉,如果這很愚蠢,我相當新! – Rafill