开发者

jQuery value true and false

IF I press key G it shows DIV if I press Enter then it runs my code but when I press G key again to hide DIV and press enter it still runs my code what I do not want to.

Here's my code:

var my_val123 = "OFF";开发者_StackOverflow

document.onkeydown = function(evt) {
    evt = evt || window.event;
    if (evt.keyCode == 71) {
        $("#mainDiv").fadeToggle("slow");
        $('#inputfield123').focus();
        my_val123 = "ON";
    }
    else if (my_val123 == 'ON' && evt.keyCode == 13) {
        //do something
    }
    else {
        my_val123 = "OFF";
    }
};


var my_val123 = "OFF";

document.onkeydown = function(evt) {
    evt = evt || window.event;
    if (my_val123 == 'OFF' && evt.keyCode == 71) {
        $("#mainDiv").fadeToggle("slow");
        $('#inputfield123').focus();
        my_val123 = "ON";
    }
    else if (my_val123 == 'ON' && evt.keyCode == 13) {
        //do something
    }
    else {
        my_val123 = "OFF";
    }
};

Regarding your comment, you must ensure that the my_val var is OFF to display the DIV, it then turns it on, if you press G again you want to turn the val off instead of executing your Enter code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜