小编Rya*_*ner的帖子

在Javascript中更改if语句中变量的值

我遇到了一段代码问题,这让我感到疯狂.我被困在这几个小时,最糟糕的是我假设它很简单; 我只是想不出来.

我正在尝试使用Javascript/jQuery创建一个简单的事件日历.这是我的简化代码:

var currentMonth = 1;
if (currentMonth == 1) {
    $("#prev-month").click( function() {
        currentMonth = 12;
    });
    $("#next-month").click( function() {
        currentMonth = 2;
    });
}
if ( currentMonth == 2) {
    $("#prev-month").click( function() {
        currentMonth = 1;
    });
    $("#next-month").click( function() {
        currentMonth = 3;
    });
}
if ( currentMonth == 3) {
    $("#prev-month").click( function() {
        currentMonth = 2;
    });
    $("#next-month").click( function() {
        currentMonth = 4;
    });
}
if ( currentMonth == 4) {
    $("#prev-month").click( function() {
        currentMonth = …
Run Code Online (Sandbox Code Playgroud)

javascript variables

3
推荐指数
1
解决办法
6831
查看次数

标签 统计

javascript ×1

variables ×1