简体   繁体   English

jQuery函数在控制台中显示,但在第一次单击时不在浏览器中显示,然后在第二次单击时在浏览器中显示两次

[英]jQuery function shows in console but not in browser on first click, then shows twice in browser on second click

I'm pretty befuddled by this bug. 这个错误让我很困惑。 Throughout my javascript file, my jQuery functions (like the one at the bottom of the page) don't act on the first click, but act twice on the second click. 在我的整个javascript文件中,我的jQuery函数(如页面底部的jQuery函数)在第一次单击时不起作用,但是在第二次单击时就起作用两次。 I'm running Bootstrap as well. 我也在运行Bootstrap。

Thanks. 谢谢。

var showLocation = function () {
    console.log("executing showLocation()\n");
    $(document).ready(function () {
            $("#show-game-button").click(function() {
                $(".location-div").show(300);
                    $("#show-game-button").css('display', 'none');
            });
    });
}

You are adding new click listener every time you execute your function. 每次执行功能时,您都将添加新的Click侦听器。 This should be working fine: 这应该工作正常:

$(document).ready(function () {
        $("#show-game-button").click(function() {
            $(".location-div").show(300);
                $("#show-game-button").css('display', 'none');
        });
});

you don't need the showLocation function. 您不需要showLocation函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery UI自动完成未显示,但显示在浏览器控制台上 - Jquery ui autocomplete not showing, but shows on browser console click()函数不在任何浏览器控制台上 - click() function does not on any browser console 使用浏览器控制台在输入字段上单击()函数 - click() function on input field using browser console 鼠标右键单击 p5.js 显示浏览器上下文菜单而不是绘图功能 - p5.js on right mouse click shows the browser context menu and not the drawing function jQuery .click()不会触发,但console.log显示输出 - jQuery .click() doesn't fire but console.log shows output 如何在第一次单击中运行jquery函数,然后在第二次单击中运行另一个函数 - How to run a jquery function in first click and another function in second click jQuery幻灯片仅在单击时显示多个幻灯片中的第一个 - jquery slideshow only shows the first of several slideshows on click 浏览器开发者控制台显示错误的文件名javascript - developer console of browser shows wrong filename javascript 值显示在浏览器控制台中,但不显示在我的终端中 - Value shows in browser console but not in my terminal Javascript单击一个元素会显示它,然后单击另一个:隐藏第一个元素并显示第二个元素 - Javascript click on one element shows it, click on another: hide the first one and show the second
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM