简体   繁体   English

当我尝试过滤表时,jQuery.trim无法正常工作

[英]jQuery.trim does not work when i try to filter a table

I have a textbox to put text in order to filter an html table. 我有一个文本框,可放置文本以过滤html表。 I want to trim the textbox contents before filter the table: 我想在过滤表之前修剪文本框的内容:

Demo : http://jsfiddle.net/QFQ5k/94/ 演示http : //jsfiddle.net/QFQ5k/94/

The line that makes the filtering is: 进行过滤的行是:

return $(this).find("[zip^='"+ $.trim($("#txtbox").val())+"']").length>0;

EDIT: It works succesfully, i tested it wrongly, but I want that alone blank space shows all table rows. 编辑:它可以成功地工作,我错误地测试了它,但是我希望单独的空白显示所有表行。

I have updated my fiddle: http://jsfiddle.net/QFQ5k/101/ 我已经更新了小提琴: http : //jsfiddle.net/QFQ5k/101/

now you can see the triming there. 现在您可以在那里看到修剪。 I just added some lines after the keyup event. 我只是在keyup事件之后添加了几行。

$("#txtbox").keyup(function () {
var a = $.trim($(this).val());
$(this).val(a);

I hope this solves what you want to achieve. 我希望这可以解决您想要实现的目标。

Better use quicksearch for your requirement. 更好地使用快速搜索来满足您的需求。 I hope below sample helps you a bit. 希望下面的示例对您有所帮助。

Quicksearch jquery plug-in QuickSearch jQuery插件

I filter only if there is something typed in the textbox, els i don't. 仅在文本框中键入某些内容时,我才会过滤,否则我不会。

if($("#txtbox").val().length >0){
   // Filtering
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM