[英]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.