所以我试图通过在其不同部分应用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;
}
有什么建议吗?提前致谢。对不起,如果这个问题措辞不正确!
答案 0 :(得分:1)
好的,我已经明白了,谢谢你们!我需要调用这个函数,我非常愚蠢地忘了这么做,所以我添加了;
mqEvents(handleMediaChange);
在底部调用mqEvents。
全部谢谢!
答案 1 :(得分:0)
具有自我功能时发送到窗口。
(function(){
window.console.log('test');
})();