728x90
function fnGetIntValueById(id) {
let intValue = document.getElementById(id).value;
intValue = (intValue === '' ? 0 : parseInt(intValue));
return intValue;
}
function fnGetStringValueById(id) {
return document.getElementById(id).value;
}
function fnGetTextById(id) {
return document.getElementById(id).textContent;
}
function fnGetCheckById(id) {
return document.getElementById(id).checked;
}
function fnGetSelectValueById(id) {
const selectHtml = document.getElementById(id);
const index = selectHtml.options.selectedIndex;
const value = selectHtml.options[index].value;
return value;
}
바닐라 자바스크립트 기반으로, 프론트쪽에서 dom의 값을 가져오는일이 빈번한데,
자주사용하는 유틸 함수를 만들어봤다.
728x90
'개발 > JavaScript' 카테고리의 다른 글
여러 select 박스를 한번에 그리는함수 (0) | 2022.12.30 |
---|---|
html의 input 의 파일 삭제 함수 (0) | 2022.12.30 |
실행 컨텍스트, 렉시컬 환경, 글로벌 환경 (0) | 2021.07.30 |
실행 컨텍스트 & 렉시컬 환경 (0) | 2021.07.25 |
객체의 상속 (0) | 2021.05.31 |