jQuery :contains(regex)? [duplicate]

雨燕双飞 提交于 2019-12-03 04:15:58

问题


Is it possible to have a jQuery selector where the :contains() is a regular expression?

I need to select an element where the innerHTML contains something findable through regex?

I know it's a short question. My apologies.

var t = $("#id a:containsRegex("/[0-9]/g")"); // Doesn't work

回答1:


Try ,

var regex = new RegExp("[0-9]"); // expression here

$("#id a").filter(function () {
    return regex.test($(this).text()); 
});


来源:https://stackoverflow.com/questions/22929862/jquery-containsregex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!