gpt4 book ai didi

javascript - 选择具有复杂 ID 模式的元素

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:44:52 24 4
gpt4 key购买 nike

我有一组这样的按钮:

<button id="grid1_createBtn">Create</button>
<button id="grid1_updateBtn">Update</button>
<button id="grid2_createBtn">Create</button>
...

这些按钮没有任何类,所以我需要通过它们的 ID 选择它们。 id 的“网格”部分是静态的,对于所有按钮都是相同的。我找到了 this answer ,但我不想使用 $("[id^=grid]"),因为可能存在起始 ID 为“grid”的其他元素。谁能帮帮我?

最佳答案

要使用正则表达式选择按钮,您可以使用 filter像这样:

$('button').filter(function(){
return /^grid\d+_\w+Btn$/.test(this.id)
})

关于javascript - 选择具有复杂 ID 模式的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30707536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com