欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

react+antd.3x實現(xiàn)ip輸入框

 更新時間:2021年10月29日 14:34:52   作者:代碼小戳  
這篇文章主要為大家詳細介紹了react+antd.3x實現(xiàn)ip輸入框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了react+antd.3x實現(xiàn)ip輸入框的具體代碼,供大家參考,具體內(nèi)容如下

表現(xiàn)形式如下:

js+html

/**
 * zks 2021 10 26
 * ip輸入框,作用于新建與修改虛擬子網(wǎng)  
 * 使用方式:參看antd-form自定義表單控件。
 */
import React  from 'react';
import { Input} from 'antd';
import styles from './index.less'
class IpInput extends React.Component{
    constructor(){
        super();
        this._refs = {
          refip_0:React.createRef(),
          refip_1:React.createRef(),
          refip_2:React.createRef(),
          refip_3:React.createRef()
        };
    }
    handleNumberChange = (e,type) => {
        //確保最小值為0;
        const number = parseInt(e.target.value || 0, 10);
        if (isNaN(number)) {
          return;
        }
        let Obj = {}
        Obj[`${type}`] = number
        this.triggerChange(Obj);
    };
    triggerChange = changedValue => {
        const { onChange, value } = this.props;
        if (onChange) {
          onChange({
            ...value,
            ...changedValue,
          });
        }
      };
    turnIpPOS = (e,type)=>{
        let self = this;
         //左箭頭向左跳轉(zhuǎn),左一不做任何措施
        if(e.keyCode === 37) {
          if(type === 0) {} else {
            self._refs[`refip_${type-1}`].current.focus();
          }
        }
        //右箭頭、回車鍵、空格鍵、冒號均向右跳轉(zhuǎn),右一不做任何措施
        if(e.keyCode === 39 || e.keyCode === 13 || e.keyCode === 32 || e.keyCode === 190) {
           if(type === 3) {} else {
            self._refs[`refip_${type+1}`].current.focus();
           }
        }
    }
    render(){
        const { value } = this.props;
        return (
            <Input.Group compact className = {styles.inputGroup}>
              <Input style={{ width: '24%' }} className = {styles.self_input} ref = {this._refs.refip_0} value = {value.ip_0} maxLength ={3} onChange={(e)=>{this.handleNumberChange(e,'ip_0')}} onKeyUp ={(e)=>this.turnIpPOS(e,0)}/>
              <span className = {styles.dot} ></span>
              <Input style={{ width: '24%' }} className = {styles.self_input} ref = {this._refs.refip_1} value = {value.ip_1} maxLength ={3} onChange={(e)=>{this.handleNumberChange(e,'ip_1')}} onKeyUp ={(e)=>this.turnIpPOS(e,1)}/>
              <span className = {styles.dot}></span>
              <Input style={{ width: '24%' }} className = {styles.self_input} ref = {this._refs.refip_2} value = {value.ip_2} maxLength ={3} onChange={(e)=>{this.handleNumberChange(e,'ip_2')}} onKeyUp ={(e)=>this.turnIpPOS(e,2)}/>
              <span className = {styles.dot}></span>
              <Input style={{ width: '24%' }} className = {styles.self_input} ref = {this._refs.refip_3} value = {value.ip_3} maxLength ={3} onChange={(e)=>{this.handleNumberChange(e,'ip_3')}} onKeyUp ={(e)=>this.turnIpPOS(e,3)}/>
            </Input.Group>
        )
    }
   
}
export default IpInput;

css

.inputGroup {
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  transition: all 0.3s;
  &:hover {
    border-color: #45bbff;
    border-right-width: 1px !important;
    outline: 0;
    box-shadow: 0 0 0 2px rgba(29, 165, 255, 0.2);
  }
  text-align: center;
  .dot {
    width: 3px;
    height: 3px;
    border: 1px solid #000;
    border-radius: 3px;
    background-color: #000;
    opacity: 0.5;
    z-index: 9;
    position: relative;
    top: 21px;
  }
}
.self_input {
  border: none;
  outline: 0px;
  &:hover {
    box-shadow: none;
  }
  &::selection {
    box-shadow: none;
  }
  &:focus {
    box-shadow: none;
  }
}

使用方式

import IPInput from '../../public/IpInput';
<FormItem label="子網(wǎng)網(wǎng)關(guān)" {...formItemLayout}>
                {getFieldDecorator('price', {
                  initialValue: { ip_0: 255, ip_1: 235, ip_2: 255, ip_3: 255 },
                  rules: [{ validator: this.checkIp }],
                })(<IPInput />)}
 </FormItem>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解開發(fā)react應(yīng)用最好用的腳手架 create-react-app

    詳解開發(fā)react應(yīng)用最好用的腳手架 create-react-app

    本篇文章主要介紹了詳解開發(fā)react應(yīng)用最好用的腳手架 create-react-app,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-04-04
  • 基于React的狀態(tài)管理實現(xiàn)一個簡單的顏色轉(zhuǎn)換器

    基于React的狀態(tài)管理實現(xiàn)一個簡單的顏色轉(zhuǎn)換器

    這篇文章主要介紹了用React的狀態(tài)管理,簡簡單單實現(xiàn)一個顏色轉(zhuǎn)換器,文中有詳細的代碼示例供大家參考,具有一定的參考價值,需要的朋友可以參考下
    2023-08-08
  • 基于react項目打包css引用路徑錯誤解決方案

    基于react項目打包css引用路徑錯誤解決方案

    這篇文章主要介紹了基于react項目打包css引用路徑錯誤解決方案,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-10-10
  • React?SSG實現(xiàn)Demo詳解

    React?SSG實現(xiàn)Demo詳解

    這篇文章主要為大家介紹了React?SSG實現(xiàn)Demo詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪<BR>
    2023-07-07
  • React中常見的TypeScript定義實戰(zhàn)教程

    React中常見的TypeScript定義實戰(zhàn)教程

    這篇文章主要介紹了React中常見的TypeScript定義實戰(zhàn),本文介紹了Fiber結(jié)構(gòu),F(xiàn)iber的生成過程,調(diào)和過程,以及 render 和 commit 兩大階段,需要的朋友可以參考下
    2022-10-10
  • 使用 Rails API 構(gòu)建一個 React 應(yīng)用程序的詳細步驟

    使用 Rails API 構(gòu)建一個 React 應(yīng)用程序的詳細步驟

    這篇文章主要介紹了使用 Rails API 構(gòu)建一個 React 應(yīng)用程序的詳細步驟,主要包括后端:Rails API部分,前端:React部分及React組件的相關(guān)操作,具有內(nèi)容詳情跟隨小編一起看看吧
    2021-08-08
  • react 可拖拽進度條的實現(xiàn)

    react 可拖拽進度條的實現(xiàn)

    本文主要介紹了react 可拖拽進度條的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • 關(guān)于react 父子組件的執(zhí)行順序

    關(guān)于react 父子組件的執(zhí)行順序

    這篇文章主要介紹了關(guān)于react 父子組件的執(zhí)行順序,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • React實踐之Tree組件的使用方法

    React實踐之Tree組件的使用方法

    本篇文章主要介紹了React實踐之Tree組件的使用方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09
  • React中多語言的配置方式

    React中多語言的配置方式

    這篇文章主要介紹了React中多語言的配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06

最新評論