几个input必须都填写否则button灰化

本文介绍了一个使用HTML、CSS、JavaScript等技术实现的输入验证案例,通过监听输入事件,动态改变提交按钮的样式,提升用户体验。重点在于如何在前端实现简单的逻辑判断,并通过CSS样式调整按钮状态。
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title></title>
    <link rel="stylesheet" href="bootstrap.min.css">
    <style type="text/css">
        body{
            padding: 30px;
        }
        a:hover,.btn1{
            font-size:1.2rem;
            border-radius:2px;
            height:2rem;
            line-height:2rem;
            color:#999;
            border-bottom:.3rem solid #bbb;
            text-align:center;
            display:block;
            background:#f5f5f5;
            text-decoration: none;
            width: 100px;

        }
    </style>
</head>
<body>
<input id="new_input_1" type="tel" maxlength="1" class="inp1"><br>
<input id="new_input_2" type="tel" maxlength="1" class="inp1"><br>
<input id="new_input_3" type="tel" maxlength="1" class="inp1"><br>
<input id="new_input_4" type="tel" maxlength="1" class="inp1"><br>
<input id="new_input_5" type="tel" maxlength="1" class="inp1"><br>
<input id="new_input_6" type="tel" maxlength="1" class="inp1"><br>
<a id="sub" class="btn1" >提交</a>

    <script type="text/javascript" src="jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="bootstrap.min.js"></script>
<script>
    var a=$("#new_input_1");
    var b=$("#new_input_2");
    var c=$("#new_input_3");
    var d=$("#new_input_4");
    var e=$("#new_input_5");
    var f=$("#new_input_6");

    $("input").on("keyup",function(){
        var mb=a.val().trim().length && b.val().trim().length && c.val().trim().length && d.val().trim().length && e.val().trim().length && f.val().trim().length;
        if(mb){
          //  alert(aa);
//            alert($(this).val());
            $("#sub").css({
                "background":"#e34f49",
                "color":"#fff",
                "border-bottom":".3rem solid #cd322c"
            });
        }else{
            $("#sub").css({
                "background":"#f5f5f5",
                "color":"#999",
                "border-bottom":".3rem solid #bbb"
            });
        }
    });


</script>

</body>
</html>
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值