jQuery:如果内容与正则表达式模式匹配,则执行此功能



我想对内部内容与正则表达式/^s*os+/m匹配的每个<p>元素运行jQuery函数。我不知道该怎么做。建议,请。。。

使用jQuery filter():

$('p').filter(function() {
    return (/^s*os+/).test($(this).text()); // return every match as jQuery obj
}).css('background-color', 'red'); // <--example, do your stuff here.
  • 演示
  • .filter()jQuery
$("p").each(function () {
   if (/^s*os+/m.test(this.innerHTML)) {
        // what to do here.
   }
})

这就是你的做法,但你应该处理正则表达式,因为我真的不知道它是做什么的。

最新更新