默認的Jquery contains方法是區分大小寫的,以下方法可以使contains不區分大小寫(在匹配時將要匹配的元素內容全部轉換成小寫再進行匹配)
// NEW selector jQuery.expr[':'].Contains = function(a, i, m) { return jQuery(a).text().toUpperCase() .indexOf(m[3].toUpperCase()) >= 0; }; // OVERWRITES old selecor jQuery.expr[':'].contains = function(a, i, m) { return jQuery(a).text().toUpperCase() .indexOf(m[3].toUpperCase()) >= 0; }; //Update to work for jQuery 1.8 $.expr[":"].contains = $.expr.createPseudo(function(arg) { return function( elem ) { return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; }; });
參考: