是否有不区分大小写的:contains jQuery Select 器版本,或者我应该通过在所有元素上循环并比较它们的大小写来手动完成这项工作.text()到我的字符串?
是否有不区分大小写的:contains jQuery Select 器版本,或者我应该通过在所有元素上循环并比较它们的大小写来手动完成这项工作.text()到我的字符串?
What I ended up doing for jQuery 1.2 is :
jQuery.extend(
jQuery.expr[':'], {
Contains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0"
});
This will extend jquery to have a :Contains selector that is case insensitive, the :contains selector remains unchanged.
编辑:对于jQuery 1.3(谢谢@user95227)和更高版本,您需要
jQuery.expr[':'].Contains = function(a,i,m){
return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0;
};
编辑:
(a.textContent || a.innerText || "")
instead of
jQuery(a).text()
In the previous expression speeds it up considerably so try at your own risk if speed is an issue. (see @John 's question)
Latest edit: For jQuery 1.8 it should be:
jQuery.expr[":"].Contains = jQuery.expr.createPseudo(function(arg) {
return function( elem ) {
return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});