简体   繁体   English

Javascript / Jquery代码跳过调试器中的全部功能

[英]Javascript/Jquery code skips whole function in debugger

function bet() {
    $('table img').css('cursor', 'pointer');
    $('table img').click(function () {
        yourBetNumber = $(this).slice(0, -1);       
        $('#item' + yourBetNumber).clone().appendTo('#yourbet');
        $('table').hide();
        $('table img').css('cursor', 'pointer');
    });
}

I have a table of items displayed, each item is a different image and has a unique ID in the html. 我有一个显示的项目表,每个项目都是不同的图像,并且在html中具有唯一的ID。 What I'm trying to do is enable the user to click on the item they want to bet on and that should be registered as their bet number. 我正在尝试做的是使用户能够单击他们想要下注的项目,并且应该将其注册为他们的下注编号。 I'm not sure the slice part is correct yet, but that's not the point - the function isn't executed at all even though I call it in the code. 我不确定切片部分是否正确,但这不是重点-即使我在代码中调用了函数,也根本不执行该函数。 The debugger also just skips over it entirely when I try to step into the next line (tried with breakpoints etc). 当我尝试进入下一行时(尝试使用断点等),调试器也会完全跳过它。

Any idea why this happens and how it could be fixed please? 知道为什么会发生这种情况以及如何解决?

You need to call bet() within the document.ready Try this 您需要在document.ready调用bet()

$('document').ready(function () {
    bet();
});
function bet(el) {
    var yourBetNumber = $(el).slice(0, -1);
    $('#item' + yourBetNumber).clone().appendTo('#yourbet');
    $('table img').hide();
}

//Setting the CSS
$(document).ready(function () {
    $('table img').css('cursor', 'pointer');
});

//AddEventHandler
$('table img').click(function () {
    bet($(this)); //Call Function "bet" with the jQuery-Object
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM