JQuery实现点击文本框等时背景变颜色

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <style type ="text/css" >
    .i{ background-color :Blue ;}
    </style>
    <script src="jquery-1.5.1.min.js" type="text/javascript"></script>
    <script type ="text/javascript" >
        $(function() {
            $("body input").focus(function() {
                $(this).addClass("i");
            }).blur(function() {
                $(this).removeClass("i");
            })
        })
    </script>
</head>

<body>
<input type ="text" />
<input type ="text" />
<input type ="button" value ="单击" />
</body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这是一个关于网页编程使用 jQuery 的问题,需要实现以下功能: 1. 两个上下输入框,一个验证按钮。 2. 输入框获得焦点输入框背景色,失去焦点后恢复原颜色。 3. 密码由数字和大小写字母中至少二种组成,长度为6至10位,密码输入后以“*”号显示,输入完成后输入框失去焦点,用正则表达式进行判断密码形式是否满足要求,输入有误在输入框后面显示输入密码类型或长度错误。 4. 从二个文本框中输入密码一致,用文本警告框提示验证通过,否则提示不通过。 5. 验证三次密码不一致,验证按钮禁用3分钟,3分钟之后解除禁止。 下面是一个简单的实现步骤: 1. HTML结构: ```html <div class="form-group"> <label for="password1">密码</label> <input type="password" class="form-control" id="password1" placeholder="请输入密码"> </div> <div class="form-group"> <label for="password2">确认密码</label> <input type="password" class="form-control" id="password2" placeholder="请再次输入密码"> </div> <button type="button" class="btn btn-primary" id="verify-btn">验证</button> ``` 2. jQuery代码: ```javascript $(document).ready(function() { var password1 = $('#password1'); var password2 = $('#password2'); var verifyBtn = $('#verify-btn'); var count = 0; // 输入框获得焦点输入框背景色,失去焦点后恢复原颜色。 password1.focus(function() { $(this).css('background-color', '#F5F5F5'); }).blur(function() { $(this).css('background-color', '#FFF'); }); password2.focus(function() { $(this).css('background-color', '#F5F5F5'); }).blur(function() { $(this).css('background-color', '#FFF'); }); // 密码输入完成后输入框失去焦点,用正则表达式进行判断密码形式是否满足要求 password1.on('input', function() { var password = $(this).val(); if (password.length < 6 || password.length > 10) { $(this).next().text('密码长度应为6至10位'); return; } if (!/[0-9]/.test(password) || !/[a-zA-Z]/.test(password)) { $(this).next().text('密码应包含数字和大小写字母中至少两种'); return; } $(this).next().text(''); }); // 确认密码输入完成后输入框失去焦点,判断两次密码是否一致 password2.on('input', function() { var password1Val = password1.val(); var password2Val = $(this).val(); if (password1Val !== password2Val) { $(this).next().text('两次输入的密码不一致'); return; } $(this).next().text(''); }); // 验证按钮点击事件 verifyBtn.click(function() { var password1Val = password1.val(); var password2Val = password2.val(); // 判断两次密码是否一致 if (password1Val !== password2Val) { alert('两次输入的密码不一致'); count++; // 验证三次密码不一致,验证按钮禁用3分钟 if (count >= 3) { verifyBtn.attr('disabled', true); setTimeout(function() { verifyBtn.attr('disabled', false); count = 0; }, 3 * 60 * 1000); } return; } alert('验证通过'); }); }); ``` 3. CSS样式: ```css .form-control:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6); box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6); } ``` 以上是一个简单的实现,具体的实现方式可以根据需要进行修改和完善。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值