+++字符添加到搜索字符串中

I am using the following to autocomplete a search field.

 $(document).on('click','li.red-red', function(){
        var foo = $('input#search').val($(this).html());
    });

It works good, but when I press enter to run the search based off of the prepopulated text a bunch of ++++++ get added to the front and back of the search string.

++++++thing+to+search+here++++++++

It seems like that the autocomplete is leaving space before and after the term it puts into the text input.

Thanks.

try using trim() to remove any space that begins or ends the string

$(document).on('click','li.red-red', function(){
        var foo = $('input#search').val($(this).text().trim());
    });