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개
게시글 목록
| 번호 | 제목 |
|---|---|
| 12181 | |
| 12180 | |
| 12179 | |
| 348 | |
| 12178 | |
| 12177 |
PHP
php환경 변수 출력 입니다.
|
| 12176 |
PHP
PHP팁 (보안 등) 입니다.
|
| 12175 |
PHP
문자열 자르는 함수 입니다.
|
| 12174 | |
| 12173 | |
| 12161 |
정규표현식
파싱 예제입니다.
11
|
| 12160 | |
| 12159 | |
| 12158 | |
| 12157 | |
| 12156 | |
| 12155 | |
| 12154 |
JavaScript
지난 시간 경과시간 페이스북 sns 처럼 보여주기 javascript 버전
|
| 12151 | |
| 12150 |
PHP
php환경맞춤 부분 입니다.
|
| 12149 | |
| 12148 | |
| 12147 | |
| 12146 | |
| 12144 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기