我有一個文本字段,用戶可以在其中搜索位置名稱。如何突出顯示結果上的文字,但不包括用戶輸入的內容顯示在結果上?以下是我在jQuery代碼:HTML中的jQuery文本突出顯示
<input maxlength="64" id="war_desc" name="searchtext" size="20" class="form200" autocomplete="off" value="">
<div class="auto-complete autocomplete_choices" data-component-bound="true" style="top: 352px; left: 352.5px; width: 172px; display: none;">
<ul>
<!-- Search result will be append here by html() -->
</ul>
</div>
<script type="text/javascript">
$('#war_desc').keyup(function(e){
var search_place = $(this).val();
if(search_place == ''){
$('.autocomplete_choices').hide();
} else {
$.ajax({
url:'".$baseUrl."business/searchnew"."',
data:{'search_place':$(this).val()},
dataType:'json',
Type:'POST',
cache:false,
success:function(data){
var listHtml = '';
for(var i=0; i<data.length; i++){
listHtml += '<li class="item" data-display-value="Shoe Exchange" title=Shoe Exchange>'+data[i]['business_name']+'</li>';
}
$('.autocomplete_choices').show();
$('.autocomplete_choices ul').html(listHtml);
}
});
}
})
</script>
以下是描述我的問題的圖像:
謝謝!
的回答,請參閱本http://stackoverflow.com/a/14164015/1920232 – peterm 2013-03-08 03:40:05
OP希望做這個答案的反面 – Popnoodles 2013-03-08 03:42:14
@peterm這是反向夥伴 – d3bug3r 2013-03-08 03:44:23