Tạo jQuery: chứa Phân biệt chữ hoa chữ thường - Thủ thuật CSS

Anonim
// 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; );

Cập nhật để hoạt động cho jQuery 1.8

$.expr(":").contains = $.expr.createPseudo(function(arg) ( return function( elem ) ( return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; ); ));

Với điều này tại chỗ,

$("div:contains('John')")

sẽ chọn cả ba yếu tố sau:

 john John hey hey JOHN hey hey 

Demo qua Pháo đài Pablo.