我正在使用下面的脚本来过滤表格中的结果。唯一的问题是它区分大小写。我如何才能使其不区分大小写?
<script>
$(document).ready(function() {
$("#searchInput").keyup(function(){
//hide all the rows
$("#fbody").find("tr").hide();
//split the current value of searchInput
var data = this.value.split(" ");
//create a jquery object of the rows
var jo = $("#fbody").find("tr");
//Recusively filter the jquery object to get results.
$.each(data, function(i, v){
jo = jo.filter("*:contains('"+v+"')");
});
//show the rows that match.
jo.show();
//Removes the placeholder text
}).focus(function(){
this.value="";
$(this).css({"color":"black"});
$(this).unbind('focus');
}).css({"color":"#C0C0C0"});
});
</script>
答案 0 :(得分:1)
http://jsfiddle.net/baeXs/和http://css-tricks.com/snippets/jquery/make-jquery-contains-case-insensitive/将帮助您
$.expr[":"].containsNoCase = $.expr.createPseudo(function(arg) {
return function( elem ) {
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
答案 1 :(得分:1)
可以使用filter()
执行类似的操作:
$.each(data, function (i, v) {
v = v.toLowerCase();
jo.filter(function () {
var txt = $(this).text().toLowerCase();
return txt.indexOf(v) > -1;
}).show();
})
答案 2 :(得分:0)
$(document).ready(function() {
$("#searchInput").keyup(function(){
//hide all the rows
$("#fbody").find("tr").hide();
//split the current value of searchInput
var data = this.value.toLowerCase().split(" ");
//create a jquery object of the rows
var jo = $("#fbody").find("tr");
//Recusively filter the jquery object to get results.
$.each(data, function(i, v){
jo = jo.filter("*:contains('"+v.toLowerCase()+"')");
});
//show the rows that match.
jo.show();
//Removes the placeholder text
}).focus(function(){
this.value="";
$(this).css({"color":"black"});
$(this).unbind('focus');
}).css({"color":"#C0C0C0"});
});
答案 3 :(得分:0)
我可能会更改过滤器:
$.each(data, function(i, v) {
jo = jo.filter(function() {
return $(this).text().toLowerCase().indexOf(v.toLowerCase()) > -1;
});
});