javascript jQuery 选择所有以 id 开头的表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3513569/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:22:59  来源:igfitidea点击:

jQuery Select all tables with id starting by

javascriptjqueryhtmljavascript-events

提问by rossale

I would like to select all the tables where the id starts with the same sentence, with jquery.

我想用jquery选择id以相同句子开头的所有表。

This what I mean:

这就是我的意思:

<table id="Tab_01">
    <tr>
        <td>....
    <tr>
    ....
</table>

<table id="Tab_02">
    <tr>
        <td>....
    <tr>
    ....
</table>
<table id="Tab_03">
    <tr>
        <td>....
    <tr>
    ....
</table>
<table id="xyz">
    <tr>
        <td>....
    <tr>
    ....
</table>

What I need, is to select the tables that start with "Tab_"and not the table with id = "xyz"

我需要的是选择以“Tab_”开头的表,而不是 id =“xyz”的表

I would like to use this code for making a similar navigation with this plugin : http://projects.allmarkedup.com/jquery_evtpaginate/demo_basic.html

我想使用此代码与此插件进行类似的导航:http: //projects.allmarkedup.com/jquery_evtpaginate/demo_basic.html

Could anyone help me ???

有人可以帮我吗???

Thanks a lot.

非常感谢。

Alessandro

亚历山德罗

回答by Ken Redler

Try this:

试试这个:

$('table[id^=Tab_]')

回答by Teja Kantamneni

Padolsey created a good plugin for this. Check it here.

Padolsey 为此创建了一个很好的插件。在这里检查。

$("table:regex(id, ^Tab)")

this is the best optimized way of doing this.

这是执行此操作的最佳优化方法。

回答by Aaron Digulla

Use a filter():

使用filter()

$('table').filter(function(index){
    return this.id.substring(0,4) == 'Tab_';
});