Javascript 如何检查链接中是否存在类?

Javascript 如何检查链接中是否存在类?,javascript,Javascript,我试图检查一个条件,如果链接包含当前类,那么我需要执行一些操作。链接具有自定义属性数据步骤 <a href="#" data-step="1" class="multistep_section">login</a> <a href="#" data-step="2" class="multistep_section">billing address</a> <a href="#" data-step="3" class="current mu

我试图检查一个条件,如果链接包含当前类,那么我需要执行一些操作。链接具有自定义属性数据步骤

<a href="#" data-step="1" class="multistep_section">login</a>
<a href="#" data-step="2" class="multistep_section">billing address</a>
<a href="#" data-step="3" class="current multistep_section">Shipping Address</a>
<a href="#" data-step="4" class="multistep_section">payment</a>
<a href="#" data-step="5" class="multistep_section">order review</a>
当data step=3将包含当前类时,我需要执行一些操作

<a href="#" data-step="1" class="multistep_section">login</a>
<a href="#" data-step="2" class="multistep_section">billing address</a>
<a href="#" data-step="3" class="current multistep_section">Shipping Address</a>
<a href="#" data-step="4" class="multistep_section">payment</a>
<a href="#" data-step="5" class="multistep_section">order review</a>
链接如下:

<a href="#" data-step="1" class="multistep_section">login</a>
<a href="#" data-step="2" class="multistep_section">billing address</a>
<a href="#" data-step="3" class="current multistep_section">Shipping Address</a>
<a href="#" data-step="4" class="multistep_section">payment</a>
<a href="#" data-step="5" class="multistep_section">order review</a>
类电流是可变的,并根据步骤进行更改。只有当data step=3包含当前类时,我才需要在jquery或javascript中执行一些操作

<a href="#" data-step="1" class="multistep_section">login</a>
<a href="#" data-step="2" class="multistep_section">billing address</a>
<a href="#" data-step="3" class="current multistep_section">Shipping Address</a>
<a href="#" data-step="4" class="multistep_section">payment</a>
<a href="#" data-step="5" class="multistep_section">order review</a>

欢迎任何建议

根据海报反馈编辑回复:

<a href="#" data-step="1" class="multistep_section">login</a>
<a href="#" data-step="2" class="multistep_section">billing address</a>
<a href="#" data-step="3" class="current multistep_section">Shipping Address</a>
<a href="#" data-step="4" class="multistep_section">payment</a>
<a href="#" data-step="5" class="multistep_section">order review</a>
$(document).ready(function(){
    if ($('a[data-step=3]').hasClass('current')){
         // Current class exists on data-step 3  
    }
});
对于纯JS:

<a href="#" data-step="1" class="multistep_section">login</a>
<a href="#" data-step="2" class="multistep_section">billing address</a>
<a href="#" data-step="3" class="current multistep_section">Shipping Address</a>
<a href="#" data-step="4" class="multistep_section">payment</a>
<a href="#" data-step="5" class="multistep_section">order review</a>
(function(){
    var elements = document.querySelectorAll('[data-step]');
    var targetElement;

    for (var i = 0; i < elements.length; i++){
        if (elements[i].getAttribute('data-step') == 3){
             targetElement = elements[i];    
        }
    }

    if (targetElement.classList.contains('current')){
        alert("Has current class");   
    }
})();
参见普通JS示例:

<a href="#" data-step="1" class="multistep_section">login</a>
<a href="#" data-step="2" class="multistep_section">billing address</a>
<a href="#" data-step="3" class="current multistep_section">Shipping Address</a>
<a href="#" data-step="4" class="multistep_section">payment</a>
<a href="#" data-step="5" class="multistep_section">order review</a>
document.AddEventListenerDomainContentLoaded,functionevent{ var links=document.getElementsByTagNamea; var class_name=当前; //如果元素包含在数组函数中 函数isInArrayvalue,数组{ 返回array.indexOfvalue>-1; } forvar i=0;i当点击链接时,你想这样做吗?不,不,点击只检查类是否存在你能告诉我如何知道哪个数据步骤有当前类吗?当数据步骤有3个值和一个类为当前类时,我需要这两个值。然后这是方法:完整代码可以在这里看到:如果我不想点击,我只想简单地检查,然后请点击我对jquery和javascript不太了解这将在页面加载后检查它是否存在:也请参见更新的响应是的,这是我真正想要的,但不是javascript。请