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년 전
와우~~ 대단하시네요 ....
멋지네요...
멋지네요...
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4530 |
라이언31
|
13년 전 | 645 | |
| 4529 | 13년 전 | 805 | ||
| 4528 |
꼬꼬아부지
|
13년 전 | 1009 | |
| 4527 | 13년 전 | 616 | ||
| 4526 | 13년 전 | 699 | ||
| 4525 |
|
13년 전 | 1024 | |
| 4524 | 13년 전 | 1001 | ||
| 4523 | 13년 전 | 2295 | ||
| 4522 | 13년 전 | 615 | ||
| 4521 | 13년 전 | 1262 | ||
| 4520 | 13년 전 | 1552 | ||
| 4519 |
복이219
|
13년 전 | 1207 | |
| 4518 | 13년 전 | 495 | ||
| 4517 | 13년 전 | 1295 | ||
| 4516 |
아이피마스터
|
13년 전 | 557 | |
| 4515 | 13년 전 | 652 | ||
| 4514 | 13년 전 | 650 | ||
| 4513 | 13년 전 | 1079 | ||
| 4512 |
ananom
|
13년 전 | 4364 | |
| 4511 |
ananom
|
13년 전 | 1479 | |
| 4510 | 13년 전 | 1224 | ||
| 4509 | 13년 전 | 690 | ||
| 4508 | 13년 전 | 851 | ||
| 4507 | 13년 전 | 937 | ||
| 4506 | 13년 전 | 708 | ||
| 4505 | 13년 전 | 636 | ||
| 4504 | 13년 전 | 482 | ||
| 4503 | 13년 전 | 526 | ||
| 4502 |
|
13년 전 | 1812 | |
| 4501 | 13년 전 | 1643 | ||
| 4500 |
|
13년 전 | 516 | |
| 4499 | 13년 전 | 1898 | ||
| 4498 | 13년 전 | 1158 | ||
| 4497 |
미션임파썩을
|
13년 전 | 891 | |
| 4496 | 13년 전 | 946 | ||
| 4495 |
공포의니이킥
|
13년 전 | 1114 | |
| 4494 | 13년 전 | 1979 | ||
| 4493 | 13년 전 | 1063 | ||
| 4492 | 13년 전 | 489 | ||
| 4491 |
두근두근따봉
|
13년 전 | 926 | |
| 4490 | 13년 전 | 1368 | ||
| 4489 |
jaein8060
|
13년 전 | 618 | |
| 4488 | 13년 전 | 1042 | ||
| 4487 |
ReeJang
|
13년 전 | 1823 | |
| 4486 | 13년 전 | 989 | ||
| 4485 | 13년 전 | 811 | ||
| 4484 | 13년 전 | 855 | ||
| 4483 | 13년 전 | 524 | ||
| 4482 | 13년 전 | 1182 | ||
| 4481 | 13년 전 | 1050 | ||
| 4480 |
|
13년 전 | 525 | |
| 4479 | 13년 전 | 917 | ||
| 4478 | 13년 전 | 3968 | ||
| 4477 | 13년 전 | 990 | ||
| 4476 |
wangko
|
13년 전 | 2711 | |
| 4475 | 13년 전 | 931 | ||
| 4474 | 13년 전 | 957 | ||
| 4473 | 13년 전 | 761 | ||
| 4472 |
|
13년 전 | 557 | |
| 4471 | 13년 전 | 1566 | ||
| 4470 | 13년 전 | 573 | ||
| 4469 | 13년 전 | 527 | ||
| 4468 | 13년 전 | 864 | ||
| 4467 | 13년 전 | 660 | ||
| 4466 | 13년 전 | 922 | ||
| 4465 | 13년 전 | 671 | ||
| 4464 | 13년 전 | 1728 | ||
| 4463 |
chongho
|
13년 전 | 2184 | |
| 4462 |
chongho
|
13년 전 | 1030 | |
| 4461 |
chongho
|
13년 전 | 1025 | |
| 4460 | 13년 전 | 756 | ||
| 4459 | 13년 전 | 2781 | ||
| 4458 | 13년 전 | 790 | ||
| 4457 | 13년 전 | 506 | ||
| 4456 | 13년 전 | 1341 | ||
| 4455 | 13년 전 | 1744 | ||
| 4454 | 13년 전 | 723 | ||
| 4453 | 13년 전 | 1255 | ||
| 4452 |
aequum
|
13년 전 | 1270 | |
| 4451 | 13년 전 | 1339 | ||
| 4450 |
도토리과자
|
13년 전 | 1437 | |
| 4449 | 13년 전 | 1093 | ||
| 4448 | 13년 전 | 8626 | ||
| 4447 | 13년 전 | 1211 | ||
| 4446 | 13년 전 | 1493 | ||
| 4445 | 13년 전 | 646 | ||
| 4444 |
|
13년 전 | 614 | |
| 4443 | 13년 전 | 698 | ||
| 4442 |
Msoft
|
13년 전 | 1062 | |
| 4441 |
|
13년 전 | 2110 | |
| 4440 | 13년 전 | 617 | ||
| 4439 | 13년 전 | 1654 | ||
| 4438 |
aequum
|
13년 전 | 1847 | |
| 4437 | 13년 전 | 993 | ||
| 4436 | 13년 전 | 925 | ||
| 4435 |
디귿소프트
|
13년 전 | 522 | |
| 4434 | 13년 전 | 1074 | ||
| 4433 | 13년 전 | 996 | ||
| 4432 | 13년 전 | 860 | ||
| 4431 | 13년 전 | 754 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기