Is there a case insensitive jQuery :contains selector?

后端 未结 12 2330
悲哀的现实
悲哀的现实 2020-11-22 02:45

Is there a case insensitive version of the :contains jQuery selector or should I do the work manually by looping over all elements and comparing their .text() to my string?<

12条回答
  •  不要未来只要你来
    2020-11-22 02:50

    To make it optionally case insensitive: http://bugs.jquery.com/ticket/278

    $.extend($.expr[':'], {
      'containsi': function(elem, i, match, array)
      {
        return (elem.textContent || elem.innerText || '').toLowerCase()
        .indexOf((match[3] || "").toLowerCase()) >= 0;
      }
    });
    

    then use :containsi instead of :contains

提交回复
热议问题