本文實例講述了jQuery實現contains方法不區分大小寫的方法。分享給大家供大家參考。具體實現方法如下:
// NEW selector jQuery.expr[':'].Contains = function(a, i, m){ return jQuery(a).text().toUpperCase() .indexOf(m[3].toUpperCase()) >= 0;}; // OVERWRITES old selecorjQuery.expr[':'].contains = function(a, i, m){ return jQuery(a).text().toUpperCase() .indexOf(m[3].toUpperCase()) >= 0;};
用法:
$("div:contains('John')")
測試HTML文件:
<div>john</div><div>John</div><div>hey hey JOHN hey hey</div>
希望本文所述對大家的jQuery程序設計有所幫助。
新聞熱點
疑難解答