jQuery正则表达式(正则表达式)

时间:2012-04-18 14:09:04

标签: javascript jquery regex

任何人对这个jQuery有所帮助我试图启动我无法使正则表达式工作

cj("input[id='PRE_TEXT_'(.*)'_POST_TEXT']").hide();

2 个答案:

答案 0 :(得分:3)

你不能在jQuery选择器中使用正则表达式。使用过滤功能:

cj("input").filter(function() {
    if (/^PRE_TEXT_(.*)_POST_TEXT$/.test(cj(this).prop("id"))) {
        return true;
    }
    return false;
}).hide();

答案 1 :(得分:2)

您不能使用正则表达式,但您应该能够使用startwith和endswith。

cj("input[id^='PRE_TEXT_'][id$='_POST_TEXT']").hide();