label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autocomplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>" ),
其中 "<strong>$1</strong>"失效了。应该怎么解决,或者都是有什么原因照成的
$( "#searchTextField" ).autocomplete({
source: function (request, response) {
var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
var local = new BMap.LocalSearch(mymap, {
// renderOptions: {map: mymap, panel: "results"},
onSearchComplete:function(results){
response($.map( results._pois, function( item ) {
var text = item.city +item.address + item.title;
if ( text && ( !request.term || matcher.test(text) ) )
return {
label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autocomplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>" ),
point: item.point,
value: item.city +item.address + item.title
}
}));
}
});
local.search(request.term);
直接用regex.replace吧,失效的原因可能是正则不对,你给信息太少了,看不出来
问题已经补充
@小小志向: 从上面的内容看语法上没问题,你检查一下正则对不对