我試圖不區分大小寫地使用「contains」。我試着用在以下計算器問題的解決方案,但它沒有工作:我該如何製作jQuery包含大小寫不敏感,包括jQuery 1.8+?
Is there a case insensitive jQuery :contains selector?
爲了方便起見,該解決方案複製到此處:
jQuery.extend(
jQuery.expr[':'], {
Contains : "jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())>=0"
});
以下是錯誤:
Error: q is not a function
Source File: /js/jquery-1.4.js?ver=1.4
Line: 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");
}
});
我原來的區分大小寫的使用「包含」在相同的情況下工作沒有任何錯誤。有沒有人有任何想法?我會很感激。
如果有人有興趣,我已經在三個附加的包含選擇器':containsExact',':containsExactCase'和''containsExactCase''上更新了我的[博客文章](http://wowmotty.blogspot.com/2010/05/jquery-selectors-adding-contains-exact.html) :containsRegex'選擇器現在可以在所有版本的jQuery中工作。 – Mottie 2012-09-02 13:08:18
請參閱https://css-tricks.com/snippets/jquery/make-jquery-contains-case-insensitive/, – 2016-11-18 20:15:56