jquery - jQuery IF值等于显示其他显示

原文 标签 jquery if-statement

我试图从输入中获取值,如果值= 1,2,3 ...以显示内容,否则,如果值= 4,5,6 ...显示其他内容。我几乎可以正常工作,然后出现故障。我已经玩了很久了。任何人都可以快速浏览一下,并指出我在哪里弄坏了它。

var amount = $(".quantity-wrapper > .input-text").val();
    if(amount = '1') {
        $('.product-addon-one-attendee').show();
    }
    if(amount = '2'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
    } 
    if(amount = '3'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
    } 
    if(amount = '4'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
    } 
    if(amount = '5'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
    }
    if(amount = '6'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
        $('.product-addon-six-attendees').show();
    }
    if(amount = '7'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
        $('.product-addon-six-attendees').show();
        $('.product-addon-seven-attendees').show();
    }
    if(amount = '8'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
        $('.product-addon-six-attendees').show();
        $('.product-addon-seven-attendees').show();
        $('.product-addon-eight-attendees').show();
    }
    if(amount = '9'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
        $('.product-addon-six-attendees').show();
        $('.product-addon-seven-attendees').show();
        $('.product-addon-eight-attendees').show();
        $('.product-addon-nine-attendees').show();
    }
    if(amount = '10'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
        $('.product-addon-six-attendees').show();
        $('.product-addon-seven-attendees').show();
        $('.product-addon-eight-attendees').show();
        $('.product-addon-nine-attendees').show();
        $('.product-addon-ten-attendees').show();
    }
    if(amount = '11'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
        $('.product-addon-six-attendees').show();
        $('.product-addon-seven-attendees').show();
        $('.product-addon-eight-attendees').show();
        $('.product-addon-nine-attendees').show();
        $('.product-addon-ten-attendees').show();
        $('.product-addon-eleven-attendees').show();
    }
    if(amount = '12'){
        $('.product-addon-one-attendee').show();
        $('.product-addon-two-attendees').show();
        $('.product-addon-three-attendees').show();
        $('.product-addon-four-attendees').show();
        $('.product-addon-five-attendees').show();
        $('.product-addon-six-attendees').show();
        $('.product-addon-seven-attendees').show();
        $('.product-addon-eight-attendees').show();
        $('.product-addon-nine-attendees').show();
        $('.product-addon-ten-attendees').show();
        $('.product-addon-eleven-attendees').show();
        $('.product-addon-twelve-attendees').show();
    }

最佳答案

if(amount = '1') // it is assigning not the comparision

正确的比较方式
if(amount === '1')

关于jquery - jQuery IF值等于显示其他显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18631336/

相关文章:

jquery - 带有可拖动图层的 clearCanvas()

jquery - 自下而上折叠DIV

javascript - 如何对jQuery选择器进行单元测试?

javascript - 如何使用jquery连续检查输入的值?

javascript - 无法在运行时将CSS样式添加到元素

excel - #N/A错误时如何使用IF语句

java - 我收到错误:cannot find symbol when compiling [closed]

java - 哪个先出现?字符还是字符串?

java - 程序来显示该值是否为字母,如果是数字,则打印“Alphabet”,然后打印“Digit”,其他字符则打印“Special Character”?

javascript - 更改文本而不使文本框失去焦点时的调用方法