Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML中的jQuery文本高亮显示_Javascript_Jquery_Html_Css_Livesearch - Fatal编程技术网

Javascript HTML中的jQuery文本高亮显示

Javascript HTML中的jQuery文本高亮显示,javascript,jquery,html,css,livesearch,Javascript,Jquery,Html,Css,Livesearch,我有一个文本字段,用户可以在其中搜索地名。如何突出显示结果上的文本,排除用户在结果上输入的内容?以下是我在jQuery中的代码: <input maxlength="64" id="war_desc" name="searchtext" size="20" class="form200" autocomplete="off" value=""> <div class="auto-complete autocomplete_choices" data-component-bou

我有一个文本字段,用户可以在其中搜索地名。如何突出显示结果上的文本,排除用户在结果上输入的内容?以下是我在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>

$('war#u desc').keyup(函数(e){ var search_place=$(this.val(); 如果(搜索位置=“”){ $('.autocomplete_choices').hide(); }否则{ $.ajax({ url:“$baseUrl.”业务/searchnew“, 数据:{'search_place':$(this.val()}, 数据类型:'json', 类型:'POST', cache:false, 成功:功能(数据){ var listHtml='';
对于(var i=0;i,使用peterm在此处找到的答案

将最后一行从

$(this).html(text.replace(new RegExp("(" + keywords.join('|') + ")" , 'gi'), "<b>$1</b>"));
$(this.html(text.replace(新的RegExp(“(“+关键字.join(“|”))+”,“gi”),“$1”);

$(this.html(“”+text.replace(newregexp(“(“+keywords.join(“|”))+”,“gi”),“$1”)+”;

您可以使用这个简单的字符串替换方法

var str = "Hello zlippr";
str = "Hello"+str.replace(str,"<b>"+str+"</b>").replace("Hello","")
document.writeln(str)
var str=“Hello zlippr”;
str=“Hello”+str.replace(str,“+str+”).replace(“Hello,”)
文件记录(str)
您的代码如下所示

data[i]['business_name'] = $(this).val()+data[i]['business_name'].replace(data[i]['business_name'],"<b>"+data[i]['business_name']+"</b>").replace($(this).val(),"")
'<li class="item" data-display-value="Shoe Exchange" title=Shoe Exchange>'+data[i]['business_name']+'</li>';
data[i]['business\u name']=$(this.val()+data[i]['business\u name'])。替换(data[i]['business\u name'],“”+data[i]['business\u name']+“”)。替换($(this.val(),“”)
“
  • ”+数据[i]['business_name']+'
  • ”;
    请参见此,了解OP想要做的与之相反的回答answer@peterm这是反向BuddyBuddy,但实际上只需要一点点的摆弄。@Popleak做得很好,谢谢。我如何将它与上面的代码一起使用?请看listHtml+=
    data[i]['business_name'] = $(this).val()+data[i]['business_name'].replace(data[i]['business_name'],"<b>"+data[i]['business_name']+"</b>").replace($(this).val(),"")
    '<li class="item" data-display-value="Shoe Exchange" title=Shoe Exchange>'+data[i]['business_name']+'</li>';