Javascript:我的Jquery事件正在存储传递给它们的对象

时间:2016-12-16 14:25:34

标签: javascript events javascript-events event-handling

我的jquery点击事件存储过去发送给它们的对象,而不是使用点击时请求的最新对象。在Javascript或Jquery中有没有办法使用最后一个对象?

$('#upgradeSkillsBar').one('click', '#position1', function(){
    console.log();
    removeSkillButton(object);
    addSkillButton(skillList[0]);
    removeRadialSubMenu(); 
});

$('#upgradeSkillsBar').one('click', '#position2', function(){
    removeSkillButton(object);
    addSkillButton(skillList[1]);
    removeRadialSubMenu(); 
});

$('#upgradeSkillsBar').one('click', '#position3', function(){
    removeSkillButton(object);
    addSkillButton(skillList[2]);
    removeRadialSubMenu(); 
});

这是我的意思的一个例子。

用户点击#position1上的事件1。

$('#upgradeSkillsBar').one('click', '#position1', function(){
    console.log();
    removeSkillButton(Skill 1);
    addSkillButton(skillList[0]);
    removeRadialSubMenu(); 
});

用户点击#position1上的事件2。

$('#upgradeSkillsBar').one('click', '#position1', function(){
    console.log();
    removeSkillButton(Skill 2);
    addSkillButton(skillList[0]);
    removeRadialSubMenu(); 
});

用户点击#position2上的第3项事件。

$('#upgradeSkillsBar').one('click', '#position2', function(){
    console.log();
    removeSkillButton(Skill 1);
    addSkillButton(skillList[0]);
    removeRadialSubMenu(); 
});

用户点击#position3上的第4项事件。

$('#upgradeSkillsBar').one('click', '#position2', function(){
    console.log();
    removeSkillButton(Skill 1);
    addSkillButton(skillList[0]);
    removeRadialSubMenu(); 
});

因此,不是使用传递给它的 last object ,而是使用第一个事件函数触发时注册的第一个对象。如何在触发事件时使用最新对象而不是第一个存储对象?

编辑:这是整个功能的列表。

function radialSelector(object){
    var skillList;
     switch (object){
        case strike:
        skillList = [poisonstrike, bluntstrike, quickstrike];
        break;
        case poisonstrike:
        skillList = [venom, immunity, toxic];
        break;
        case bluntstrike:
        skillList = [eviscerate, bruteforce, revenge];
        break;
        case quickstrike:
        skillList = [nimblelance, whirlwind, backstab];
        break;
        case defend:
        skillList = [holdtheline, quickrecovery, repairarmor];
        break;
        case holdtheline:
        skillList = [stronghold, titan, heavyarmor];
        break;
        case quickrecovery:
        skillList = [impenetrable, untouchable, fortifiedarmor];
        break;
        case repairarmor:
        skillList = [stonewall, stout, unbreakablearmor];
        break;
        case cure:
        skillList = [cura, blessing, healingwind];  
        break;
        case debuff:
        skillList = [lowerstrength, lowerarmor, loweragility];
        break;
        default:
        console.log("radialSelector() has set its switch statement to default")
    }

    for (var i=0, l=skillList.length; i<l; i++) {
    radialSubMenuSkills("position"+(i+1), skillList[i]);
    }


    $('#upgradeSkillsBar').one('click', '#position1', function(){
        console.log();
        removeSkillButton(object);
        addSkillButton(skillList[0]);
        removeRadialSubMenu(); 
    });

    $('#upgradeSkillsBar').one('click', '#position2', function(){
        removeSkillButton(object);
        addSkillButton(skillList[1]);
        removeRadialSubMenu(); 
    });

    $('#upgradeSkillsBar').one('click', '#position3', function(){
        removeSkillButton(object);
        addSkillButton(skillList[2]);
        removeRadialSubMenu(); 
    });

}

是什么叫它:

function strikeSkill() {
    activeCheck();
    if (upgradeActive == true){
        radialSelector(strike);
    }   
    if (upgradeActive == false){
    HitCalc(player.cc, monster.cc);
    actor.expCounter(player.cc);
    actor.balanceCounter(player.cc, monster.cc);
    }
};

0 个答案:

没有答案