六位input输入框的短信验证码(PC jQ)

本文介绍如何使用jQuery实现一个六位数字的输入框,适用于PC端的短信验证码验证。提供了完整的HTML代码示例,需要注意正确引入相关的JS和CSS文件。
摘要由CSDN通过智能技术生成

六位input输入框的短信验证码(PC) jQ

这里写图片描述

这里写图片描述

完整代码直接复制下边html,注意引入js css 文件

<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
    <script src="../js/commonJs/jquery-1.8.3.min.js"></script>
    <title>六位input输入框的短信验证码(PC) </title>
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css"/>
    <style>
        /*弹框验证码*/
        .ipt-fake-box {
            text-align: center;
        }
        .input {
            display: inline-block;
        }
        .input:last-child {
            border-right: 1px solid #999;
        }
        input.my_input {
            border-top: 1px solid #999;
            border-bottom: 1px solid #999;
            border-left: 1px solid #999;
            width: 45px;
            height: 45px;
            outline: none;
            font-family: inherit;
            font-size: 28px;
            font-weight: inherit;
            text-align: center;
            line-height: 45px;
            color: #c2c2c2;
            background: rgba(255, 255, 255, 0);
        }
    </style>
    <script src="../js/commonJs/bootstrap.min.js">
实现输入框短信验证码功能,可以使用 Vue.js 的模板语法和组件化思想,具体实现步骤如下: 1. 创建一个包含输入框和发送验证码按钮的组件。 ```html <template> <div> <input type="text" v-model="code" /> <button @click="sendCode" :disabled="disabled">{{ buttonText }}</button> </div> </template> <script> export default { data() { return { code: '', disabled: false, buttonText: '发送验证码', countdown: 60 } }, methods: { sendCode() { // 发送短信验证码 // ... // 设置倒计时 this.disabled = true; this.buttonText = `${this.countdown}s 后重新发送`; const timer = setInterval(() => { this.countdown--; this.buttonText = `${this.countdown}s 后重新发送`; if (this.countdown === 0) { clearInterval(timer); this.disabled = false; this.buttonText = '发送验证码'; this.countdown = 60; } }, 1000); } } } </script> ``` 2. 在父组件中引入该组件,并监听子组件的输入事件。 ```html <template> <div> <sms-code @input="handleInput" /> <button @click="submit">提交</button> </div> </template> <script> import SmsCode from './SmsCode.vue'; export default { components: { SmsCode }, data() { return { phone: '', code: '' } }, methods: { handleInput(value) { this.code = value; }, submit() { // 提交表单 // ... } } } </script> ``` 在子组件中,使用 `v-model` 来实现与父组件的双向数据绑定。当输入框的值发生变化时,通过 `$emit` 方法将新的值传递给父组件。 ```html <template> <div> <input type="text" v-model="code" @input="$emit('input', code)" /> <button @click="sendCode" :disabled="disabled">{{ buttonText }}</button> </div> </template> <script> export default { data() { return { code: '', disabled: false, buttonText: '发送验证码', countdown: 60 } }, methods: { sendCode() { // 发送短信验证码 // ... // 设置倒计时 this.disabled = true; this.buttonText = `${this.countdown}s 后重新发送`; const timer = setInterval(() => { this.countdown--; this.buttonText = `${this.countdown}s 后重新发送`; if (this.countdown === 0) { clearInterval(timer); this.disabled = false; this.buttonText = '发送验证码'; this.countdown = 60; } }, 1000); } } } </script> ``` 这样就可以实现一个简单的输入框短信验证码功能了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值