从autocomplete的li元素中删除空格和换行符

时间:2016-07-04 14:43:54

标签: jquery css autocomplete line-breaks removing-whitespace

当专注于具有换行符的自动提示时,它仅在输入中使用额外的空格进行渲染。 但是在建议中选择它显示正常。

任何解决方案?在输入和li元素上尝试white-space: nowrap并尝试运行一个函数从li中删除任何额外的空格 使用replace(/<br\s?\/?>/, '')

This is how it looks in the console:

And this is how the input and the suggestion looks like:

这是我写过的自动完成代码:

$(function() {  

  $( "#searchPageQuery" ).autocomplete({
    source: getSuggestionsSearchPage,
    autoFocus: false,
    minLength: 2,
    select: function ( event, ui ) {
      window.location = ui.item.url;
      }
  });
});


function getSuggestionsSearchPage ( request, response ) {
  var params = $("input:checked[name='labels']").serializeArray();
  var query = { name:"q", value:request.term };
  params.push( query )
  var params1 = jQuery.param( params );
  $.ajax({
  dataType: "json",
  url: "@{AutocompleteSearchR}",
  data: params1,
  success: function(data) {
    var newdata = data.suggestions;
    response(newdata);
    }
  });
  }

0 个答案:

没有答案