简体   繁体   English

变量更改为1后,调用某些内容。

[英]after a variable change to 1, call something.. javascript

So Basicly if i click the burtton, it should change the variables to 1. However, it dosen't print out "It's happening now" as it should. 因此,基本上,如果我单击Burtton,则应将变量更改为1。但是,它不会像应该的那样打印出“它正在发生”。

Could someone please explain what's wrong with this?? 有人可以解释这是怎么回事吗?

Best regards daniel. 最好的问候丹尼尔。

var reg_uname_done = 0;
var reg_pword1_done = 0;
var reg_pword2_done = 0;
var reg_email_done = 0;


$("#first_nav_bar li:first").click(function(event) {
    reg_uname_done = 1;
    reg_pword1_done = 1;
    reg_pword2_done = 1;
    reg_email_done = 1;
}); 



if(reg_pword1_done === 1 && reg_pword2_done === 1 && reg_email_done === 1 && reg_uname_done === 1) {
    console.log('its happening now');
}

The reason why this is not happening is b/c the js file is going down, and you haven't "clicked" the <li> element yet, therefore your variables are still equal to 0. You have to set a function inside of that event. 发生这种情况的原因是b / c js文件正在关闭,并且您尚未“单击” <li>元素,因此您的变量仍等于0。您必须在其中设置一个函数那件事。

See fiddle 见小提琴

var reg_uname_done = 0;
var reg_pword1_done = 0;
var reg_pword2_done = 0;
var reg_email_done = 0;

$("#first_nav_bar li:first").click(function (event) {
    reg_uname_done = 1;
    reg_pword1_done = 1;
    reg_pword2_done = 1;
    reg_email_done = 1;

    check();
})

function check() {
    if (reg_pword1_done === 1 && reg_pword2_done === 1 && reg_email_done && reg_uname_done) {
        console.log('its happening now');
    }
}

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

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