gpt4 book ai didi

javascript - 如何停用 console.log 和警报?

转载 作者:行者123 更新时间:2023-11-28 02:36:19 24 4
gpt4 key购买 nike

作为一名新手,我在尝试学习 JavaScript 时经常使用 console.log 和alert()。我找到了一个我感兴趣的网站,并将 html 和 javascript/jquery 复制到我的本地主机上来使用它。当我将 console.log() 和警报语句放入 JavaScript 中以帮助解决问题时,它们都不起作用。我在多个浏览器(Chrome、Safari、Firefox)中尝试过此操作,删除浏览器历史记录等。对我来说,代码没有什么异常。我可能缺少什么吗?代码运行良好(控制台中没有记录任何错误)。

顺便说一句,我将其复制到本地主机上,因为我不知道如何在 Firebug 中添加控制台日志。有没有办法做到这一点?我从 console.log 获得的信息比设置断点更多(我理解的)。

这是代码。这显然相当简单(尽管我仍然需要 console.log 才能完全获取它)。

// Global variables
var flag;
var dark;

$(document).ready(function() {
// $(function() {

// Hide all closed sections
$(".closed").next().hide();

// Add slide functions to all sections (h1 elements)
$("h1").click(function () {
if($(this).is('.closed')) {
$(".open").delay(200, function() { $(this).next().slideUp("slow"); });
$(this).delay(200, function() { $(this).next().slideDown("slow"); });
$("h1").deactivateElement();
$(this).activateElement();
}
else if($(this).is('.open')) {
$(this).delay(200, function() { $(this).next().slideUp("slow"); });
$(this).deactivateElement();
}
});

// Add a function to toggle the CSS styles
$("a#style_switcher").click(function () { flag = !flag; dark.disabled = flag; });

// Add hover functions to all sections (h1 elements)
$("h1").hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });


// Delay the call to (slide) functions
// => http://james.padolsey.com/javascript/jquery-delay-plugin/
$.fn.delay = function(time, callback) {
jQuery.fx.step.delay = function() {};
return this.animate( { delay: 1 }, time, callback);
}

// Set an element class to 'open' or 'closed'
$.fn.activateElement = function() { switchClasses($(this), 'open', 'closed'); }
$.fn.deactivateElement = function() { switchClasses($(this), 'closed', 'open'); }

// Do this at start
initialize(console.log("farting"));
alert("hi");

$(".who").delay(600, function() { $(this).next().slideDown("slow"); });
$(".who").activateElement();
});


// Initialization function
function initialize () {
flag = true;
dark = document.getElementById("dark_css");
dark.disabled = flag;



// Set year in copyright section
document.getElementById('year').innerHTML = (new Date()).getFullYear();
}

// Utility function for switching/toggling classes
function switchClasses (element, classToAdd, classToRemove) {



element.addClass(classToAdd);
element.removeClass(classToRemove);
// De/Activate the given element
(classToAdd == 'open') ? element.addClass('active') : element.removeClass('active');
}

最佳答案

针对您的标题,如下:

window.alert = function () { }
alert('hi');

不触发。

关于javascript - 如何停用 console.log 和警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13436713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com