duanke1286 2016-10-15 05:43
浏览 382
已采纳

Javascript隐藏/显示按钮[关闭]

I'm trying to hide/show a button on my form depending on whether the credit card validation returns true. So they can click checkout if it is true, and otherwise they cannot.

<script>
    $(function test() {

        $('#cardNo').validateCreditCard(function (result) {

            $('.log').html('Card type: ' + (result.card_type == null ? '-' : result.card_type.name)
                    + '<br>Valid: ' + result.valid
                    + '<br>Length valid: ' + result.length_valid
                    + '<br>Luhn valid: ' + result.luhn_valid);
            console.log(result.valid);
            console.log(result.length_valid);
            console.log(result.luhn_valid);
            if (result.valid == true && result.length_valid == true && result.luhn_valid == true) {
                console.log('we have entered the if statement');
                document.getElementById("checkoutButton").style.dislay = 'block';
            }
            else {
                console.log('we are not in the if statement');
                document.getElementById("checkoutButton").style.display = 'none';
            }
        });
    });
</script>

I have verified that when I enter a correct credit card number, we do go into the if statement. The console will read 'we have entered the if statement'. However, the checkout button will not become visible on the page.

I am wondering if it is even possible to do something like this in javascript? Thanks for the help!

  • 写回答

3条回答 默认 最新

  • dongshangan2074 2016-10-15 05:52
    关注

    just replace your code with this one:

                if (result.valid == true && result.length_valid == true && result.luhn_valid == true) {
                    console.log('we have entered the if statement');
                    document.getElementById("checkoutButton").style.display = 'block';
                }
                else {
                    console.log('we are not in the if statement');
                    document.getElementById("checkoutButton").style.display = 'none';
                }
    

    That's it, Enjoy coding :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料