gpt4 book ai didi

javascript - jQuery - 如何选择变量的后缀并在数组中找到它的匹配项

转载 作者:太空宇宙 更新时间:2023-11-04 14:43:45 25 4
gpt4 key购买 nike

我有一系列的选择:

var options = ["foo_A", "foo_B", "foo_C", "foo_D"];

...当用户点击以下元素之一时...

<div id="bar_A"> </div>
<div id="bar_B"> </div>
<div id="bar_C"> </div>
<div id="bar_D"> </div>

...它设置以下变量:

var currentBar = $(this).attr('id');

...然后我想搜索选项数组并找到其后缀与 currentBar 的后缀匹配的项目,如下所示:

 $.each(options, function(i,v){
if (v's suffix matches the currentBar's suffix){

//function to do something

}

最佳答案

$.each(options, function(i,v){
if (options[i].split("_")[1] == currentBar.split("_")[1]){

//function to do something

}

关于javascript - jQuery - 如何选择变量的后缀并在数组中找到它的匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11231268/

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