[warning]
개인적으로.. 내가 배운 것, 내가 느낀 것 위주로 적는 내용이기 때문에, 남이 볼때 못알아 볼 가능성이 크다.
[문제점]
전에 modal을 사용 해봤지만, ajax로 값을 서버를 통해 주고 받았기 때문에, modal에 입력한 값을 서버에 전송 없이, 바로 input창으로 옮겨 받는 법을 몰랐다.
youtube와 googling 결과, 방법을 알아냈다.
<script type="text/javascript">
$(document).ready(function() {
//selectBtn은 모달 창에서 완료 버튼
$('#selectBtn').click(function(){
//country는 모달창 안에 있는 input창 id
var country = $('#myModal #country').val().trim();
//country_eng는 모달창 밖에 값을 넣고싶은 input창 id
document.getElementById('#country_eng').value = country;
//완료버튼을 눌러도 모달창이 안없어지길래 hide 명령 넣어줌
$('#myModal').modal('hide');
});
});
</script>
[궁금점 1]
여기서 궁금한게 생겼는데, trim() 이라는 함수! 무엇인지 궁금해져서 googling 시도.
문자열 좌 우 에서 공백을 제거하는 함수라고 한다.
.trim() 양쪽 공백 제거,
.ltrim() 왼쪽 공백 제거,
.rtrim() 오른쪽 공백 제거
라고 한다.
[궁금점 2]
getElementById() 함수란?
Id 값으로 특정한 요소를 가져온다. 내가 값을 넣어주고 싶은 id를 적는다.
** input 창에 값을 넣고싶을때 사용합니다. (내가 오늘 하루종일 찾던 그것...)
자세한 영어 설명 링크
https://www.javatpoint.com/document-getElementById()-method
JavaScript - document.getElementById() method - javatpoint
Document.getElementById() method in javascript with example, What are the usage of document.getElementById() method? Explanation of getElementById() method is given below with examples.
www.javatpoint.com
'SOFTWARE > TIL' 카테고리의 다른 글
[JavaScript] map/reduce/forEach/findIndex (0) | 2021.01.10 |
---|---|
블록체인에 대해.. (0) | 2020.03.05 |
mail protocol 관련 용어 정리들! (0) | 2020.03.05 |
2020.02.18 - 용어 정리 (0) | 2020.02.18 |
[JavaScript] Arrays (0) | 2020.01.31 |
댓글