gpt4 book ai didi

JQuery 基于类字符串中的第一个进行选择

转载 作者:行者123 更新时间:2023-12-01 07:33:14 25 4
gpt4 key购买 nike

我有两个元素,它们是小选项卡脚本的基础。由于各种原因(称为 Internet Exploder 6),我不得不像这样构建它:

选项卡标题

<span class="Block1 inactive" id="Tab1">Label1</span>
<span class="Block2 inactive" id="Tab2">Label2</span>
<span class="Block3 inactive" id="Tab3">Label3</span>

标签内容

<div class="contents inactive" id="Block1 ">Stuff here</div>
<div class="contents inactive" id="Block2 ">Stuff here</div>
<div class="contents inactive" id="Block3 ">Stuff here</div>

因此,当单击 Tab1 时,我的脚本需要获取“Block1”的类,然后搜索具有匹配类或 ID 的 div。

但是我怎样才能在一组多个类中选择第一个类呢?有这样的事情吗?这可能吗?

var tabtoshow = $(this).attr('class':first);
var tabtoshow = $(this).attr('class:first');
var tabtoshow = $(this).attr('class[0]');

卡住了...

谢谢!

最佳答案

我认为没有比这更好的解决方案了:

var tabtoshow = $(this).attr('class').split(' ')[0];

...类的相对顺序通常没有任何意义,所以我认为没有任何帮助。

关于JQuery 基于类字符串中的第一个进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4376071/

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