做一个防百度的模糊搜索查询下拉;
先写一个input输入框;下载Download Builder | jQuery UI 插件
<tr class="table-responsive">
<td>
店铺名称:
<input type="text" name="phName" value="" id="phName" placeholder="模糊搜索," class="rph" size='50' >
<input type="hidden" name="rpId" id="rpId" />
</td>
</tr>
<script>
window.onload=function(){
$(".rph").autocomplete({
minLength: 0,
source: function( request, response ) {
//干你想干的事情
$.ajax({
url : "__CONTROLLER__/getshopcode",
type : "post",
dataType : "json",
data : {"shopname":$(".rph").val()},
success: function( data ) {
console.log(data);
response( $.map( data, function( item ) {
return {
label: item.shopname,
value: item.shopcode
}
}));
}
});
},
focus: function( event, ui ) {
$(".rph").val( ui.item.label );
$("#rpId").val( ui.item.value );
return false;
},
select: function( event, ui ) {
console.log(ui);
$(".rph").val( ui.item.label );
$("#rpId").val( ui.item.value );
}
}
}
})
}