jQuery .search() to any string

后端 未结 3 1390
生来不讨喜
生来不讨喜 2020-12-05 12:28

I saw this code snippet:

$(\"ul li\").text().search(new RegExp(\"sometext\", \"i\"));

and wanted to know if this can be extended to any str

3条回答
  •  广开言路
    2020-12-05 12:48

    Ah, that would be because RegExp is not jQuery. :)

    Try this page. jQuery.attr doesn't return a String so that would certainly cause in this regard. Fortunately I believe you can just use .text() to return the String representation.

    Something like:

    $("li").val("title").search(/sometext/i));
    

提交回复
热议问题