http://sir.co.kr/bbs/board.php?bo_table=pg_qa&wr_id=4055
이 글을 보고 간단히 만들어 봤습니다.
index.html
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Real-time Address</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="application.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<select>
<option value="">광역시/도</option>
</select>
<select>
<option value="">시/도/군</option>
</select>
<select>
<option value="">읍/면/동</option>
</select>
</div>
</body>
</html>
stylesheet.css
body {
font-size: 12px;
background: #FFF;
color: #333;
margin: 0;
}
#content {
margin: 30px;
padding: 20px;
background: #7CF;
}
application.js
$(function() {
var uniqueId = 0;
function ajaxYqlWithJson(options) {
var callbackName = 'my_yql_callback_' + ++uniqueId;
window[callbackName] = options.callback;
var yql = 'SELECT * FROM json WHERE url="' + encodeURIComponent(options.url) + '"';
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql?q=' + yql +
'&format=json&callback=' + callbackName,
dataType: 'script',
complete: function() {
delete window[callbackName];
}
});
}
function createSelectCallback(index) {
return function(data) {
var select = $('select').eq(index);
$(data.query.results.result.subRegion).each(function(i, region) {
$('<option></option>').attr('value', region.code).text(region.name)
.appendTo(select);
});
};
}
function clearSelect(select) {
select.html(select.children().first());
}
function ajaxGetRegions(options) {
var level = options.level;
var code = options.code;
if (code && level <= 8) {
ajaxYqlWithJson({
url: 'http://map.naver.com/common2/getBRegionByCodeAndLevel.nhn' +
'?level=' + level + '&code=' + code,
callback: options.callback
});
}
}
$('select').each(function(index, select) {
$(select).change(function() {
for (var i = index + 1; i < $('select').length; i++) {
clearSelect($('select').eq(i));
}
ajaxGetRegions({
level: 2 + 3 * (index + 1),
code: $(this).val(),
callback: createSelectCallback(index + 1)
})
});
});
ajaxYqlWithJson({
url: 'http://map.naver.com/common2/getBRegionByCodeAndLevel.nhn?level=2',
callback: createSelectCallback(0)
});
});
이 글을 보고 간단히 만들어 봤습니다.
index.html
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Real-time Address</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="application.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
<select>
<option value="">광역시/도</option>
</select>
<select>
<option value="">시/도/군</option>
</select>
<select>
<option value="">읍/면/동</option>
</select>
</div>
</body>
</html>
stylesheet.css
body {
font-size: 12px;
background: #FFF;
color: #333;
margin: 0;
}
#content {
margin: 30px;
padding: 20px;
background: #7CF;
}
application.js
$(function() {
var uniqueId = 0;
function ajaxYqlWithJson(options) {
var callbackName = 'my_yql_callback_' + ++uniqueId;
window[callbackName] = options.callback;
var yql = 'SELECT * FROM json WHERE url="' + encodeURIComponent(options.url) + '"';
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql?q=' + yql +
'&format=json&callback=' + callbackName,
dataType: 'script',
complete: function() {
delete window[callbackName];
}
});
}
function createSelectCallback(index) {
return function(data) {
var select = $('select').eq(index);
$(data.query.results.result.subRegion).each(function(i, region) {
$('<option></option>').attr('value', region.code).text(region.name)
.appendTo(select);
});
};
}
function clearSelect(select) {
select.html(select.children().first());
}
function ajaxGetRegions(options) {
var level = options.level;
var code = options.code;
if (code && level <= 8) {
ajaxYqlWithJson({
url: 'http://map.naver.com/common2/getBRegionByCodeAndLevel.nhn' +
'?level=' + level + '&code=' + code,
callback: options.callback
});
}
}
$('select').each(function(index, select) {
$(select).change(function() {
for (var i = index + 1; i < $('select').length; i++) {
clearSelect($('select').eq(i));
}
ajaxGetRegions({
level: 2 + 3 * (index + 1),
code: $(this).val(),
callback: createSelectCallback(index + 1)
})
});
});
ajaxYqlWithJson({
url: 'http://map.naver.com/common2/getBRegionByCodeAndLevel.nhn?level=2',
callback: createSelectCallback(0)
});
});
댓글 6개
14년 전
서버 없이 돌아가는 코드를 만들기 위해 네이버 지도가 사용하는 API를 몰래 썼습니다.
실제로 서비스하실 땐 저 부분을 바꿔줘야겠죠? 그러면 YQL을 쓸 이유도 없구요.
실제로 서비스하실 땐 저 부분을 바꿔줘야겠죠? 그러면 YQL을 쓸 이유도 없구요.
14년 전
내공이 상당하신 분 같네요^^
좋은 팁 자주 올려주시면 감사하겠습니다~
좋은 팁 자주 올려주시면 감사하겠습니다~
14년 전
짧은 코드안에 jquery의 많은 부분이 심플하게 구성되어 있네요.
jquery 공부하는 입장에서도 좋은 소스같습니다.
감사합니다.
jquery 공부하는 입장에서도 좋은 소스같습니다.
감사합니다.
행복한남자
14년 전
감사합니다...^^
14년 전
서버에 올려놨습니다. 어떤 건지 결과물부터 보고 싶은 분은... http://j.mp/vRyafl
13년 전
와우~~ 대단하시네요 ....
멋지네요...
멋지네요...
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4730 |
제너레이션
|
13년 전 | 1002 | |
| 4729 | 13년 전 | 943 | ||
| 4728 | 13년 전 | 701 | ||
| 4727 | 13년 전 | 1245 | ||
| 4726 | 13년 전 | 849 | ||
| 4725 | 13년 전 | 1681 | ||
| 4724 | 13년 전 | 1020 | ||
| 4723 | 13년 전 | 2689 | ||
| 4722 | 13년 전 | 560 | ||
| 4721 |
ECEditor
|
13년 전 | 2233 | |
| 4720 | 13년 전 | 2615 | ||
| 4719 | 13년 전 | 4383 | ||
| 4718 | 13년 전 | 960 | ||
| 4717 | 13년 전 | 1174 | ||
| 4716 | 13년 전 | 1351 | ||
| 4715 |
한번잘해보자
|
13년 전 | 1168 | |
| 4714 | 13년 전 | 1177 | ||
| 4713 | 13년 전 | 2827 | ||
| 4712 | 13년 전 | 1250 | ||
| 4711 |
김준수사랑
|
13년 전 | 1013 | |
| 4710 |
한번잘해보자
|
13년 전 | 1146 | |
| 4709 | 13년 전 | 1142 | ||
| 4708 | 13년 전 | 817 | ||
| 4707 | 13년 전 | 1701 | ||
| 4706 |
프로프리랜서
|
13년 전 | 2088 | |
| 4705 |
프로프리랜서
|
13년 전 | 1379 | |
| 4704 | 13년 전 | 968 | ||
| 4703 |
프로프리랜서
|
13년 전 | 935 | |
| 4702 | 13년 전 | 832 | ||
| 4701 | 13년 전 | 1568 | ||
| 4700 | 13년 전 | 2596 | ||
| 4699 | 13년 전 | 1309 | ||
| 4698 |
|
13년 전 | 1599 | |
| 4697 |
|
13년 전 | 1118 | |
| 4696 |
|
13년 전 | 1135 | |
| 4695 |
|
13년 전 | 1345 | |
| 4694 |
|
13년 전 | 864 | |
| 4693 |
|
13년 전 | 855 | |
| 4692 |
|
13년 전 | 858 | |
| 4691 |
|
13년 전 | 1186 | |
| 4690 |
|
13년 전 | 1271 | |
| 4689 |
|
13년 전 | 1018 | |
| 4688 |
|
13년 전 | 779 | |
| 4687 |
|
13년 전 | 1055 | |
| 4686 |
|
13년 전 | 1009 | |
| 4685 |
|
13년 전 | 940 | |
| 4684 |
|
13년 전 | 1041 | |
| 4683 |
|
13년 전 | 932 | |
| 4682 |
|
13년 전 | 1243 | |
| 4681 |
|
13년 전 | 1019 | |
| 4680 |
|
13년 전 | 1139 | |
| 4679 |
|
13년 전 | 1653 | |
| 4678 |
|
13년 전 | 580 | |
| 4677 | 13년 전 | 2913 | ||
| 4676 |
복이219
|
13년 전 | 616 | |
| 4675 | 13년 전 | 816 | ||
| 4674 | 13년 전 | 614 | ||
| 4673 | 13년 전 | 989 | ||
| 4672 | 13년 전 | 934 | ||
| 4671 | 13년 전 | 1198 | ||
| 4670 | 13년 전 | 718 | ||
| 4669 | 13년 전 | 1778 | ||
| 4668 | 13년 전 | 1420 | ||
| 4667 |
너는나의봄이다
|
13년 전 | 1020 | |
| 4666 | 13년 전 | 6695 | ||
| 4665 | 13년 전 | 621 | ||
| 4664 | 13년 전 | 999 | ||
| 4663 | 13년 전 | 843 | ||
| 4662 | 13년 전 | 972 | ||
| 4661 | 13년 전 | 1244 | ||
| 4660 | 13년 전 | 841 | ||
| 4659 | 13년 전 | 1102 | ||
| 4658 |
소나무닷컴
|
13년 전 | 686 | |
| 4657 | 13년 전 | 707 | ||
| 4656 |
|
13년 전 | 1241 | |
| 4655 | 13년 전 | 3099 | ||
| 4654 | 13년 전 | 673 | ||
| 4653 | 13년 전 | 2097 | ||
| 4652 | 13년 전 | 873 | ||
| 4651 | 13년 전 | 775 | ||
| 4650 | 13년 전 | 1664 | ||
| 4649 | 13년 전 | 1600 | ||
| 4648 | 13년 전 | 609 | ||
| 4647 | 13년 전 | 1506 | ||
| 4646 | 13년 전 | 1935 | ||
| 4645 | 13년 전 | 1334 | ||
| 4644 | 13년 전 | 610 | ||
| 4643 | 13년 전 | 2023 | ||
| 4642 | 13년 전 | 814 | ||
| 4641 |
|
13년 전 | 605 | |
| 4640 | 13년 전 | 566 | ||
| 4639 |
|
13년 전 | 1294 | |
| 4638 |
|
13년 전 | 1665 | |
| 4637 |
|
13년 전 | 1135 | |
| 4636 | 13년 전 | 625 | ||
| 4635 | 13년 전 | 758 | ||
| 4634 | 13년 전 | 1262 | ||
| 4633 | 13년 전 | 1245 | ||
| 4632 |
|
13년 전 | 539 | |
| 4631 | 13년 전 | 3341 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기