[Javascript] 파라미터, 자바스크립트 변수로 받기

호호빵·2022년 7월 12일

input

# readonly
<input readonly type="text">

# input 태그에 value 넣기
<input type="text" value="" name="inputValue"/>
$('input[name=inputValue]').attr('value',"test");

-> <input type="text" value="test" name="inputValue"/>

1000단위 콤마 표시

var price = 10000;
price.toLocaleString(); // 10,000

필요 파라미터 값 들고오기

function getParams() {
        const curUrl = window.location.href;
        const url = new URL(curUrl);

        const urlParams = url.searchParams;

        let weekdayPrice = urlParams.get('weekdayPrice');
        let weekendPrice = urlParams.get('weekendPrice');
        console.log(weekdayPrice);

        $('#eventPrice').val(eventPrice(weekdayPrice, weekendPrice));
    }

input 태그의 값을 자바스크립트 함수의 변수로 할당

function getDatesStartToLast() {
        let startDate = document.getElementById('datePicker-start').value;
        let lastDate = document.getElementById('datePicker-end').value;
        let curDate = new Date(startDate);
        while (curDate <= new Date(lastDate)) {
            results.push(curDate.toISOString().split("T")[0]);
            curDate.setDate(curDate.getDate() + 1);
        }
        findDate(results);
    }
    
<input id="datePicker-start" type="text" th:field="*{eventStartDate}" class="form-control" placeholder="시작일">
<input id="datePicker-end" th:field="*{eventEndDate}" class="form-control" placehold="종료일">

input readonly
input에 value 넣기
현재 페이지 URL 가져오기
필요 파라미터 가져오기
onchange 함수
타임리프 자바스크립트 변수 사용 - 예약된 날짜 처리
타임리프 기본기능
input 태그의 값을 함수의 변수로 사용

profile
하루에 한 개념씩

0개의 댓글