jQuery的:包含(正则表达式)? [英] jQuery :contains(regex)?

查看:144
本文介绍了jQuery的:包含(正则表达式)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个jQuery选择器,其中:contains()是正则表达式?

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

我需要选择一个元素,其中innerHTML包含可通过正则表达式找到的内容?

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

推荐答案

尝试,

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

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

这篇关于jQuery的:包含(正则表达式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆