소스 검색

数字组件允许输入.等黏贴无法判断

zhouna 6 년 전
부모
커밋
153eef096b
1개의 변경된 파일3개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      src/components/NumberDrop/index.jsx

+ 3 - 1
src/components/NumberDrop/index.jsx

@@ -118,7 +118,9 @@ class NumberDrop extends Component{
     handleEnter();
     //只能输入数字
     const key = e.key;
-    if(!/[0-9]/.test(key)){
+    const ctrlOn = e.ctrlKey;
+    const isCopyPaste = ctrlOn&&(key=='v'||key=='c');
+    if(!/[0-9|.|~|\/]/.test(key)&&key.length==1&&!isCopyPaste){
       e.preventDefault();
       return false;
     }