728x90
๋ฐ์ํ
[Api]
์นด์นด์ค ์ฃผ์์ฐพ๊ธฐ api
: kakao html input text api
HTML / CSS / JS
โ ์ํฉ
→ ํ์๊ฐ์ ํผ์ด๋ ๋ง์ดํ์ด์ง ๋ฑ ํ์ ์ ๋ณด ๋ฑ๋ก์์ ํํ ๋ณผ ์ ์๋ ์ฃผ์ ์ฐพ๊ธฐ ๊ธฐ๋ฅ ๊ตฌํํ๊ณ ์ถ์ ๋
โ ๋ฐฉ๋ฒ
→ ์นด์นด์ค ์ฃผ์์ฐพ๊ธฐ Api ์ฌ์ฉ
โ ์ฌ์ฉ ๋ฐฉ๋ฒ
→ HTML ์์ฑ
→ CSS input ๋์์ธ
→ JS ์ฐ๋ ๋ฐ ์ ํ ์ ๋ ฅ๊ฐ ์ธํ
๐ข ์๋์์ ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ์ ํ์ธํ ์ ์์ต๋๋ค.
https://postcode.map.daum.net/guide
๐ ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<script>
new daum.Postcode({
oncomplete: function(data) {
// ํ์
์์ ๊ฒ์๊ฒฐ๊ณผ ํญ๋ชฉ์ ํด๋ฆญํ์๋ ์คํํ ์ฝ๋๋ฅผ ์์ฑํ๋ ๋ถ๋ถ์
๋๋ค.
// ์์ ๋ฅผ ์ฐธ๊ณ ํ์ฌ ๋ค์ํ ํ์ฉ๋ฒ์ ํ์ธํด ๋ณด์ธ์.
}
}).open();
</script>
๐ด ์๋ ์ฝ๋ ์ ์ฉ์ ์คํ ํ๋ฉด
๐ฃ ์ ์ฒด ์ฝ๋ demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kakao API</title>
<!-- css, js ์ฐ๊ฒฐ -->
<link rel="stylesheet" href="../common/css/style.css">
<script src="../common/js/joinForm.js"></script>
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
<!-- css -->
<style>
.join_group {
box-sizing: border-box;
padding: 5px 0px 5px 0px;
}
.join_group > label {
display: inline-block;
box-sizing: border-box;
width: 110px;
margin: 0px 15px 0px 10px;
font-size: 14px;
}
.join_group > input {
box-sizing: border-box;
width : 380px;
height : 45px;
padding : 5px 0px 0px 10px;
margin: 0px 10px 0px 0px;
border-radius: 5px;
border: 1px solid #D9D9D9;
font-size: 12px;
}
.join_group .btn_address {
box-sizing: border-box;
width : 380px;
height : 45px;
padding : 5px 0px 0px 10px;
margin: 0px 10px 0px 0px;
border-radius: 5px;
border: 1px solid #D9D9D9;
font-size: 13px;
color : #a3a3a3;
cursor: pointer;
}
.join_group > .detail_address {
margin: 10px 0px 0px 140px;
cursor: pointer;
}
</style>
</head>
<body>
<form action="" method="">
<!-- ์ฃผ์ -->
<div class="join_group">
<label class="" for="">์ฃผ์*</label>
<input type="text" id="address_kakao" name="address" value="" placeholder="์ฃผ์ ๊ฒ์" readonly />
<input type="text" id="detail_address" class="detail_address" name="address_detail" value="" placeholder="์์ธ์ฃผ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์">
</div>
</form>
</body>
<script>
window.onload = function(){
document.getElementById("address_kakao").addEventListener("click", function(){ //์ฃผ์์
๋ ฅ์นธ์ ํด๋ฆญํ๋ฉด
//์นด์นด์ค ์ง๋ ๋ฐ์
new daum.Postcode({
oncomplete: function(data) { //์ ํ์ ์
๋ ฅ๊ฐ ์ธํ
document.getElementById("address_kakao").value = data.address; // ์ฃผ์ ๋ฃ๊ธฐ
document.querySelector("input[name=address_detail]").focus(); //์์ธ์
๋ ฅ ํฌ์ปค์ฑ
}
}).open();
});
}
</script>
</html>
๐ข HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kakao API</title>
<!-- css, js ์ฐ๊ฒฐ -->
<link rel="stylesheet" href="../common/css/style.css">
<script src="../common/js/joinForm.js"></script>
<script src="//t1.daumcdn.net/mapjsapi/bundle/postcode/prod/postcode.v2.js"></script>
</head>
<body>
<form action="" method="">
<!-- ์ฃผ์ -->
<div class="join_group">
<label class="" for="">์ฃผ์*</label>
<input type="text" id="address_kakao" name="address" value="" placeholder="์ฃผ์ ๊ฒ์" readonly />
<input type="text" id="detail_address" class="detail_address" name="address_detail" value="" placeholder="์์ธ์ฃผ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์">
</div>
</form>
</body>
</html>
๐ CSS
@charset "UTF-8";
.join_group {
box-sizing: border-box;
padding: 5px 0px 5px 0px;
}
.join_group > label {
display: inline-block;
box-sizing: border-box;
width: 110px;
margin: 0px 15px 0px 10px;
font-size: 14px;
}
.join_group > input {
box-sizing: border-box;
width : 380px;
height : 45px;
padding : 5px 0px 0px 10px;
margin: 0px 10px 0px 0px;
border-radius: 5px;
border: 1px solid #D9D9D9;
font-size: 12px;
}
/* ์ฃผ์ */
.join_group .btn_address {
box-sizing: border-box;
width : 380px;
height : 45px;
padding : 5px 0px 0px 10px;
margin: 0px 10px 0px 0px;
border-radius: 5px;
border: 1px solid #D9D9D9;
font-size: 13px;
color : #a3a3a3;
cursor: pointer;
}
.join_group > .detail_address {
margin: 10px 0px 0px 140px;
cursor: pointer;
}
๐ต JS
// ์ฃผ์์ฐฝ ๋์ฐ๊ธฐ
$(document).ready(function () {
document.getElementById("address_kakao").addEventListener("click", function(){ //์ฃผ์์
๋ ฅ์นธ์ ํด๋ฆญํ๋ฉด
//์นด์นด์ค ์ง๋ ๋ฐ์
new daum.Postcode({
oncomplete: function(data) { //์ ํ์ ์
๋ ฅ๊ฐ ์ธํ
document.getElementById("address_kakao").value = data.address; // ์ฃผ์ ๋ฃ๊ธฐ
document.querySelector("input[name=address_detail]").focus(); //์์ธ์
๋ ฅ ํฌ์ปค์ฑ
}
}).open();
});
});
728x90
๋ฐ์ํ