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년 전
와우~~ 대단하시네요 ....
멋지네요...
멋지네요...
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4630 | 13년 전 | 1189 | ||
| 4629 | 13년 전 | 4362 | ||
| 4628 | 13년 전 | 766 | ||
| 4627 |
|
13년 전 | 1755 | |
| 4626 | 13년 전 | 810 | ||
| 4625 |
마릴릴모니
|
13년 전 | 723 | |
| 4624 | 13년 전 | 1634 | ||
| 4623 |
SIR정회원
|
13년 전 | 602 | |
| 4622 |
rakoos
|
13년 전 | 1571 | |
| 4621 | 13년 전 | 676 | ||
| 4620 | 13년 전 | 1458 | ||
| 4619 | 13년 전 | 984 | ||
| 4618 | 13년 전 | 4032 | ||
| 4617 | 13년 전 | 2031 | ||
| 4616 | 13년 전 | 853 | ||
| 4615 | 13년 전 | 677 | ||
| 4614 | 13년 전 | 1245 | ||
| 4613 | 13년 전 | 880 | ||
| 4612 |
rakoos
|
13년 전 | 1020 | |
| 4611 |
|
13년 전 | 2109 | |
| 4610 | 13년 전 | 765 | ||
| 4609 | 13년 전 | 2819 | ||
| 4608 | 13년 전 | 2800 | ||
| 4607 | 13년 전 | 1076 | ||
| 4606 | 13년 전 | 772 | ||
| 4605 | 13년 전 | 2316 | ||
| 4604 | 13년 전 | 889 | ||
| 4603 | 13년 전 | 1141 | ||
| 4602 |
한번잘해보자
|
13년 전 | 679 | |
| 4601 | 13년 전 | 1804 | ||
| 4600 |
|
13년 전 | 1087 | |
| 4599 |
크라운엠버서더
|
13년 전 | 1152 | |
| 4598 | 13년 전 | 1500 | ||
| 4597 | 13년 전 | 594 | ||
| 4596 | 13년 전 | 3662 | ||
| 4595 |
|
13년 전 | 907 | |
| 4594 | 13년 전 | 1787 | ||
| 4593 | 13년 전 | 1280 | ||
| 4592 | 13년 전 | 657 | ||
| 4591 | 13년 전 | 4645 | ||
| 4590 | 13년 전 | 515 | ||
| 4589 | 13년 전 | 2633 | ||
| 4588 |
|
13년 전 | 990 | |
| 4587 | 13년 전 | 645 | ||
| 4586 |
JavaDD
|
13년 전 | 1013 | |
| 4585 | 13년 전 | 7780 | ||
| 4584 | 13년 전 | 972 | ||
| 4583 |
PHPㅡASP프로그래머
|
13년 전 | 2061 | |
| 4582 |
PHPㅡASP프로그래머
|
13년 전 | 1499 | |
| 4581 |
PHPㅡASP프로그래머
|
13년 전 | 1021 | |
| 4580 | 13년 전 | 4084 | ||
| 4579 |
|
13년 전 | 688 | |
| 4578 | 13년 전 | 1188 | ||
| 4577 | 13년 전 | 811 | ||
| 4576 |
Kanzi
|
13년 전 | 866 | |
| 4575 |
|
13년 전 | 1548 | |
| 4574 | 13년 전 | 2341 | ||
| 4573 |
달빛소나타
|
13년 전 | 875 | |
| 4572 | 13년 전 | 994 | ||
| 4571 | 13년 전 | 939 | ||
| 4570 |
|
13년 전 | 1306 | |
| 4569 |
한번잘해보자
|
13년 전 | 555 | |
| 4568 |
Raizond
|
13년 전 | 1018 | |
| 4567 |
Raizond
|
13년 전 | 523 | |
| 4566 |
Revenge
|
13년 전 | 941 | |
| 4565 |
|
13년 전 | 694 | |
| 4564 |
|
13년 전 | 1138 | |
| 4563 | 13년 전 | 1560 | ||
| 4562 | 13년 전 | 1210 | ||
| 4561 | 13년 전 | 9392 | ||
| 4560 | 13년 전 | 1773 | ||
| 4559 | 13년 전 | 3345 | ||
| 4558 | 13년 전 | 468 | ||
| 4557 | 13년 전 | 1446 | ||
| 4556 | 13년 전 | 702 | ||
| 4555 | 13년 전 | 548 | ||
| 4554 | 13년 전 | 541 | ||
| 4553 |
|
13년 전 | 4307 | |
| 4552 | 13년 전 | 1509 | ||
| 4551 | 13년 전 | 1994 | ||
| 4550 | 13년 전 | 681 | ||
| 4549 | 13년 전 | 1037 | ||
| 4548 | 13년 전 | 1571 | ||
| 4547 | 13년 전 | 554 | ||
| 4546 | 13년 전 | 1617 | ||
| 4545 | 13년 전 | 1334 | ||
| 4544 | 13년 전 | 3023 | ||
| 4543 | 13년 전 | 1012 | ||
| 4542 | 13년 전 | 2263 | ||
| 4541 | 13년 전 | 1138 | ||
| 4540 |
|
13년 전 | 1060 | |
| 4539 | 13년 전 | 1156 | ||
| 4538 | 13년 전 | 1587 | ||
| 4537 | 13년 전 | 1172 | ||
| 4536 | 13년 전 | 549 | ||
| 4535 |
|
13년 전 | 824 | |
| 4534 |
|
13년 전 | 982 | |
| 4533 | 13년 전 | 648 | ||
| 4532 |
soing
|
13년 전 | 7377 | |
| 4531 |
|
13년 전 | 6398 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기