如何使jQuery包含不區(qū)分大小寫的內(nèi)容,包括jQuery 1.8+?我試圖不敏感地使用“包含”一詞。我嘗試在下面的堆棧溢出問題上使用該解決方案,但沒有成功:是否有不區(qū)分大小寫的jQuery:包含選擇器?為了方便起見,在這里復(fù)制解決方案:jQuery.extend(
jQuery.expr[':'], {
Contains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0" });以下是錯誤:Error: q is not a functionSource File: /js/jquery-1.4.js?ver=1.4Line: 81這里是我使用它的地方: $('input.preset').keyup(function() {
$(this).next().find("li").removeClass("bold");
var theMatch = $(this).val();
if (theMatch.length > 1){
theMatch = "li:Contains('" + theMatch + "')";
$(this).next().find(theMatch).addClass("bold");
}
});在相同的場景中,我使用了區(qū)分大小寫的“Content”,沒有任何錯誤。有人有什么想法嗎?我會很感激的。
3 回答

慕森卡
TA貢獻1806條經(jīng)驗 獲得超8個贊
jQuery.expr[':'].Contains = function(a, i, m) { return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; };
jQuery.expr[":"].Contains = jQuery.expr.createPseudo(function(arg) { return function( elem ) { return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; };});

撒科打諢
TA貢獻1934條經(jīng)驗 獲得超2個贊
:Contains
:contains
jQuery.expr[':'].Contains = function(a, i, m) { return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; };jQuery.expr[':'].contains = function(a, i, m) { return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; };

鴻蒙傳說
TA貢獻1865條經(jīng)驗 獲得超7個贊
$.expr[':'].containsIgnoreCase = function (n, i, m) { return jQuery(n).text().toUpperCase().indexOf(m[3].toUpperCase()) >= 0; };
:contains
- 3 回答
- 0 關(guān)注
- 284 瀏覽
添加回答
舉報
0/150
提交
取消