부트 스트랩을 사용하고있는 경우 (그렇지 않은 경우) 선구자를 사용할 수 있습니다. (google typeahead.bundle.js)
부트 스트랩 이후에이 자바 스크립트 파일을 호출하십시오.
그런 다음 당신은 그럼 당신은 입력 그런
<input id="mytextquery" name="mytextquery" type="text" size="71" maxlength="128" value="" placeholder="Carrier (type to search)" class="form-control typeahead"/>
페이지에 약간의 자바 스크립트를 필요로 약간의 CSS
<style>
.typeahead,
.tt-query,
.tt-hint {
font-size: 12px;
}
.typeahead {
background-color: #fff;
}
.typeahead:focus {
border: 2px solid #0097cf;
}
.tt-query {
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
-moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}
.tt-hint {
color: #999
}
.tt-menu {
width: 422px;
margin: 12px 0;
padding: 8px 0;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
-webkit-box-shadow: 0 5px 10px rgba(0,0,0,.2);
-moz-box-shadow: 0 5px 10px rgba(0,0,0,.2);
box-shadow: 0 5px 10px rgba(0,0,0,.2);
}
.tt-suggestion {
padding: 3px 20px;
font-size: 18px;
line-height: 24px;
}
.tt-suggestion:hover {
cursor: pointer;
color: #fff;
background-color: #0097cf;
}
.tt-suggestion.tt-cursor {
color: #fff;
background-color: #0097cf;
}
.tt-suggestion p {
margin: 0;
}
.gist {
font-size: 14px;
}
이 필요합니다.
<script>
$(function() {
$('#mytextquery').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
limit: 12,
async: true,
source: function (query, processSync, processAsync) {
return $.ajax({
url: "typeTest.php",
type: 'GET',
data: {query: query},
dataType: 'json',
success: function (json) {
// in this example, json is simply an array of strings
return processAsync(json);
}
});
}
});
});
</script>
그런 다음 당신은 당신의 데이터베이스에서 데이터를 가져 오기 위해 사용하는 어떤 일부 PHP 또는
$query = $_GET['query'];
//Do your SQL query here
$query = "SELECT * from table where field LIKE '$query'";
//Get results and format like below
$data1 = [ 'Item 1', 'Item 2', 'Item 3' ,'etc', 'etc'];
//Export it so typeahead can read it.
header('Content-type: application/json');
echo json_encode($data1);
이 지금까지 완벽하게 보인다. 곧 테스트 해봐. 먼저 SSL을 통한 연결을 허용하도록 MariaDB를 구성해야합니다. – smallpants
나는이 사이트에서 firebase 호스팅을 사용하고 있다는 사실이 서버 측 코드가 작동하지 않는다는 것을 의미합니다. 뒤로 10 걸음 ... – smallpants