프로젝트 데모를 위해 jQuery 주소 자동 완성 프로토 타입을 신속하게 작성합니다.jQuery 자동 완성 드롭 다운을 사용하여 입력 내용을 표시합니다.
기본적으로 사용자가 초기 입력 필드에 주소를 입력하면 가능한 주소 (addresspicker-style)의 드롭 다운 목록이 자동으로 표시됩니다.
입력란에 입력되는 내용을 반영하기 위해 "입력 한 주소 :"주소 목록의 첫 번째 항목으로 삽입하면됩니다.
참조 :
http://jsfiddle.net/hotdiggity/NFeEH/
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Autocomplete</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<style>
#results { float: right; }
#address { float: left; }
</style>
<script>
$(function() {
$("#results").hide();
var addresses = [{
value: "25/167 Smith",
add1: "25/167 Smith Street",
loc: "Brisbane",
state: "Queensland",
postcode: "4000"
}, {
value: "25/167 Smith",
add1: "25/167 Smith Street",
loc: "Mandaring",
state: "WESTERN AUSTRALIA",
postcode: "6073"
}, {
value: "25/167 Smith",
add1: "25/167 Smith Creek Road",
loc: "Werombi",
state: "NEW SOUTH WALES",
postcode: "2570"
}, {
value: "25/167 Smith",
add1: "25/167 Smith Street",
loc: "Collingwood Park",
state: "QUEENSLAND",
postcode: "4301"
}, {
value: "Level 25/167 Smith",
add1: "25/167 Smith Terrace",
loc: "Auchenflower",
state: "QUEENSLAND",
postcode: "4066"
},
];
$("#address").autocomplete({
minLength: 0,
source: addresses,
focus: function(event, ui) {
// $("#address").val(ui.item.add1 + ", " + ui.item.loc + ", " + ui.item.state + " " + ui.item.postcode);
return false;
},
select: function(event, ui) {
$("#address").val(ui.item.label);
// $("#address-id").val(ui.item.value);
$("#address-add1").val(ui.item.add1);
$("#address-loc").val(ui.item.loc);
$("#address-state").val(ui.item.state);
$("#address-postcode").val(ui.item.postcode);
$("#results").show();
return false;
}
})
.data("ui-autocomplete")._renderItem = function(ul, item) {
return $("<li>")
.append("<a>" + item.add1 + ", " + item.loc + ", " + item.state + " " + item.postcode + "</a>")
.appendTo(ul);
};
});
</script>
</head>
<body>
<p>Start by typing "25"</p>
<input id="address" />
<div id="results">
<p>
<input id="address-add1" />
</p>
<p>
<input id="address-loc" />
</p>
<p>
<input id="address-state" />
</p>
<p>
<input id="address-postcode" />
</p>
</div>
</body>
</html>
입니다 ? –