简体   繁体   English

使用 JQuery 在列表元素中获取动态 Class 名称?

[英]Get Dynamic Class Names in List Element with JQuery?

I want to identify order steps on a website...我想确定网站上的订单步骤...

Through the 5 five steps, the url is not changing... only the tabs class names are changing through the process.通过 5 个五个步骤,url 没有改变……只有选项卡 class 的名称在整个过程中发生变化。

Tabs class name on step 1:第 1 步中的标签 class 名称:

<ul class="step clearfix" id="order_step">

<li class="step_current first"> <span>Recap</span></li>
<li class="step_todo second"> <span> Connexion</span></li>
<li class="step_todo third"> <span> Address</span></li>
<li class="step_todo four"> <span> Delivery</span></li>
<li id="step_end" class="step_todo last"> <span> Paiement</span></li>

</ul>

Tabs class name on step 2:第 2 步中的标签 class 名称:

<ul class="step clearfix" id="order_step">

<li class="step_done first"> <span>Recap</span></li>
<li class="step_current second"> <span> Connexion</span></li>
<li class="step_todo third"> <span> Address</span></li>
<li class="step_todo four"> <span> Delivery</span></li>
<li id="step_end" class="step_todo last"> <span> Paiement</span></li>

</ul>

How to use JQuery to get the class name matching "step_current"?如何使用 JQuery 获得与“step_current”匹配的 class 名称?

Here what I was looking for (I'm not a JS expert so I was mixing up operators):这就是我要找的东西(我不是 JS 专家,所以我混淆了运算符):

$("li.step_current")[0].textContent

So I can retrieve the title of the active tab.所以我可以检索活动选项卡的标题。

Thanks for the helpful comments.感谢您的有用评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM