Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.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
Php +++;添加到搜索字符串中的字符_Php_Jquery_Search_Post - Fatal编程技术网

Php +++;添加到搜索字符串中的字符

Php +++;添加到搜索字符串中的字符,php,jquery,search,post,Php,Jquery,Search,Post,我正在使用以下命令自动完成搜索字段 $(document).on('click','li.red-red', function(){ var foo = $('input#search').val($(this).html()); }); 它工作得很好,但当我按enter键运行基于 预填充文本在搜索字符串的前面和后面添加了一堆++ ++++++thing+to+search+here++++++++ 似乎自动完成在输入文本的术语前后都留下了空间 谢谢 尝试使用tri

我正在使用以下命令自动完成搜索字段

 $(document).on('click','li.red-red', function(){
        var foo = $('input#search').val($(this).html());
    });
它工作得很好,但当我按enter键运行基于 预填充文本在搜索字符串的前面和后面添加了一堆++

++++++thing+to+search+here++++++++
似乎自动完成在输入文本的术语前后都留下了空间

谢谢

尝试使用
trim()
删除字符串开头或结尾的任何空格

$(document).on('click','li.red-red', function(){
        var foo = $('input#search').val($(this).text().trim());
    });
尝试使用
trim()
删除字符串开头或结尾的任何空格

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

你能发布完整的代码吗?
$(this).html()
似乎有问题…我也在使用$(this).text()你能发布完整的代码吗?
$(this).html()
似乎有问题…我也在使用$(this.text())