如何实施' if'某些价值观?

时间:2013-05-22 11:08:15

标签: jquery if-statement

我再次对jquery不熟悉,并试图让这个办公空间计算器工作。 当我的“total”值发生变化时,我想使用单独的动画。 就像选择1并选择“calculate”一样,播放动画。

Here where my widget is

$(document).ready(function () {
    $('#arrow-right').click(function () {
        if (parseInt($('#total').text()) < 3) {
          $('#total').text(parseInt($('#total').text()) + 1);
        }
    });
})
$(document).ready(function () {
    $('#arrow-left').click(function () {
        if (parseInt($('#total').text()) > 1) {
           $('#total').text(parseInt($('#total').text()) - 1);
        }
    });
})
$(document).ready(function () {
    $("#calculate").click(function () {
        if ('#total' == 1) {
            $("#requirements-contact").css("display", "block");
            $("#space-calculator").animate({
                height: '595px'
            }, "slow");
            var div = $("#space-total, #thousands, #hundreds, #tens, #units");
            div.animate({
                display: 'toggle'
            }, "slow");
            div.animate({
                bottom: '-895px'
            }, "slow");
            var div = $("#hundreds");
            div.animate({
                bottom: '-695px'
            }, "slow");
            var div = $("#tens");
            div.animate({
                bottom: '-395px'
            }, "slow");
            var div = $("#units");
            div.animate({
                bottom: '-195px'
            }, "slow");
        }
        if ('#total' == 2) {
            $("#requirements-contact").css("display", "block");
            $("#space-calculator").animate({
                height: '595px'
            }, "slow");
            var div = $("#space-total, #thousands, #hundreds, #tens, #units");
            div.animate({
                display: 'toggle'
            }, "slow");
            div.animate({
                bottom: '-895px'
            }, "slow");
            var div = $("#hundreds");
            div.animate({
                bottom: '-695px'
            }, "slow");
            var div = $("#tens");
            div.animate({
                bottom: '-395px'
            }, "slow");
            var div = $("#units");
            div.animate({
                bottom: '-195px'
            }, "slow");
        }
        if ('#total' == 3) {
            $("#requirements-contact").css("display", "block");
            $("#space-calculator").animate({
                height: '595px'
            }, "slow");
            var div = $("#space-total, #thousands, #hundreds, #tens, #units");
            div.animate({
                display: 'toggle'
            }, "slow");
            div.animate({
                bottom: '-895px'
            }, "slow");
            var div = $("#hundreds");
            div.animate({
                bottom: '-695px'
            }, "slow");
            var div = $("#tens");
            div.animate({
                bottom: '-395px'
            }, "slow");
            var div = $("#units");
            div.animate({
                bottom: '-195px'
            }, "slow");
        }
    });
})

1 个答案:

答案 0 :(得分:0)

如果我理解正确您需要做的是:$('#total').val()如果它是可编辑的输入类型元素(如<input id='total' type="text">)。如果它只是一个元素内的文本(如<span id="total">1<div>') what you need to do is: $('#total')。text()`来获取文本。

这是完整的鳕鱼:

if ($('#total').val() == 3) {
  //do what you need to do...

}

 if ($('#total').text() == 3) {
      //do what you need to do...

 }

希望这就是你要求的。