본문 바로가기

개발이야기/Javascript

(14)
html에서 this 인자 전달 test click onclick으로 this 인자 전달 가능
자바스크립트 업로드 이미지 파일 크기 확인 //파일 용량 let maxSize = 5 * 1024 * 1024; //5MB let _URL = window.URL || window.webkitURL; let file; let uploadImg = document.getElementById("image"); if (uploadImg) { let imageFile = document.getElementById("image").files[0]; let imageFileSize = document.getElementById("image").files[0].size; if ((file = imageFile)) { let img = new Image(); let objectUrl = _URL.createObjectURL(file); img.onload = ..
자바스크립트 숫자만 추출 onlyNumber: function(number) { if (typeof number == "number") { return number; } let result = number.replace(/[^0-9]/g, ""); return Number(result); }, if (typeof number == "number") { return number; } TIP : 타입이 number 일때는 TypeError 발생함으로 체크
javascript 반복문에서 setTimeout 1초 간격 호출하기 반복문에 1초 간격으로 호출 하고 싶을때는 let delay = 0; for(let i=0; i { //실행할 함수명 }, delay); } 위와 같이 진행 해야 1초 간격으로 호출이 될수 있다 for(let i=0; i { //실행할 함수명 }, 1000); } 이렇게 하면 1초 뒤 count 만큼의 함수가 한번에 호출 됨 더 좋은 방법이 있다면 댓글로 남겨 주시면 감사하겠습니다.
전화번호 "-" 자동 입력 정규식 hp.replace(/[^0-9]/g, "").replace(/(^02|^0505|^1[0-9]{3}|^0[0-9]{2})([0-9]+)?([0-9]{4})$/, "$1-$2-$3" );
자바스크립트 GET 파라메터 받기 자바스크립트로 GET 파라메터를 쉽게 받기 위해 검색하다 보니 알게된 함수 let params = new URLSearchParams(window.location.search); let param_type = params .get("type"); 익스프로러에서는 지원이 안된다고 하는데 익스프로러에서도 console.log가 잘 찍히는걸 확인