6位交易密码框

import React, { Component } from 'react'
import { Form, Input } from 'antd';

export default class Passwordbeifen extends Component {
    constructor(props) {
        super(props)
        this.password1 = React.createRef()
        this.password2 = React.createRef()
        this.password3 = React.createRef()
        this.password4 = React.createRef()
        this.password5 = React.createRef()
        this.password6 = React.createRef()
        this.state = {
            number: []
        }
    }

    confirm = (e) => {
        if (e.keyCode == 37 || e.keyCode == 38) {
            e.preventDefault()
        }
    }
    changeValue = (num, e) => {

        let { number } = this.state
        number[num] = e.target.value


        this.props.getValue(number)

    }
    changePassword1 = (e) => {

        if (this.password1.current.state.value !== '') {
            if (e.keyCode == 37) {
                this.password6.current.focus();
            } else {
                this.password2.current.focus();
            }

        }
        if (e.keyCode == 39) {//向后
            this.password2.current.focus();
        }

    }
    changePassword2 = (e) => {
        if (this.password2.current.state.value !== '') {
            this.password3.current.focus();
        }
        if (e.keyCode == 8 && this.password2.current.state.value == '') {  //删除
            this.password1.current.focus()
        } else if (e.keyCode == 37) {//向前
            e.preventDefault()
            this.password1.current.focus()
        } else if (e.keyCode == 39) {//向后
            this.password3.current.focus();
        }

    }
    changePassword3 = (e) => {
        if (this.password3.current.state.value !== '') {
            this.password4.current.focus();
        }
        if (e.keyCode == 8 && this.password3.current.state.value == '') {
            this.password2.current.focus()
        } else if (e.keyCode == 37) {//向前
            e.preventDefault()
            this.password2.current.focus()
        } else if (e.keyCode == 39) {//向后
            this.password4.current.focus();
        }

    }
    changePassword4 = (e) => {
        if (this.password4.current.state.value !== '') {
            this.password5.current.focus();
        }
        if (e.keyCode == 8 && this.password4.current.state.value == '') {
            this.password3.current.focus()
        } else if (e.keyCode == 37) {//向前
            e.preventDefault()
            this.password3.current.focus()
        } else if (e.keyCode == 39) {//向后
            this.password5.current.focus();
        }
    }
    changePassword5 = (e) => {
        if (this.password5.current.state.value !== '') {
            this.password6.current.focus();
        }
        if (e.keyCode == 8 && this.password5.current.state.value == '') {
            this.password4.current.focus()
        } else if (e.keyCode == 37) {//向前
            e.preventDefault()
            this.password4.current.focus()
        } else if (e.keyCode == 39) {//向后
            this.password6.current.focus();
        }
    }
    changePassword6 = (e) => {

        if (e.keyCode == 8 && this.password6.current.state.value == '') {

            this.password5.current.focus()
        } else if (e.keyCode == 37) {//向前
            e.preventDefault()
            this.password5.current.focus()
        }
    }
    render() {
        return (
            <div className='loan'>
                <>
                    <div>
                        <Input type='tel' ref={this.password1} className='input_password' maxLength={1} onKeyUp={this.changePassword1.bind(this)} onKeyDown={this.confirm.bind(this)} onChange={this.changeValue.bind(this, 0)} />
                        <Input type='tel' ref={this.password2} className='input_password' maxLength={1} onKeyUp={this.changePassword2.bind(this)} onKeyDown={this.confirm.bind(this)} onChange={this.changeValue.bind(this, 1)} />
                        <Input type='tel' ref={this.password3} className='input_password' maxLength={1} onKeyUp={this.changePassword3.bind(this)} onKeyDown={this.confirm.bind(this)} onChange={this.changeValue.bind(this, 2)} />
                        <Input type='tel' ref={this.password4} className='input_password' maxLength={1} onKeyUp={this.changePassword4.bind(this)} onKeyDown={this.confirm.bind(this)} onChange={this.changeValue.bind(this, 3)} />
                        <Input type='tel' ref={this.password5} className='input_password' maxLength={1} onKeyUp={this.changePassword5.bind(this)} onKeyDown={this.confirm.bind(this)} onChange={this.changeValue.bind(this, 4)} />
                        <Input type='tel' ref={this.password6} className='input_password' maxLength={1} onKeyUp={this.changePassword6.bind(this)} onKeyDown={this.confirm.bind(this)} onChange={this.changeValue.bind(this, 5)} />
                    </div>

                </>
            </div>
        )
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值