0
나는 특정 클래스가 있거나 클래스가 없거나 두 클래스가없는 텍스트를 얻으려고합니다. 여기 하나 이상의 클래스를 확인하십시오.
내 HTML 코드입니다 - 내가 빈 클래스를 갖는 링크 태그()li
가진 '
t-completed
'클래스와 어떤의 텍스트 싶어하고, 지금
<div id="events">
<ul class="checkout-bar">
<li class=""><span><a href="#">Order</a></span></li>
<li class=""><span><a href="#">Booking</a></span></li>
<li class="t-completed"><span><a href="#">Receiving</a></span></li>
<li class="t-completed"><span><a href="#">Loading</a></span></li>
<li class="t-completed active"><span><a href="#">Arrival</a></span></li>
<li class="inactive"><span><a href="#">Arrival</a></span></li>
<li class="inactive"><span><a href="#">Availability</a></span></li>
<li class="inactive"><span><a href="#">Delivery</a></span></li>
</ul>
</div>
있는이없는 't-completed
'와 'active
'클래스 즉 <li class="t-completed active">
jQuery로 시도 -
if($('#events .checkout-bar li').length>0){
$('#events .checkout-bar li').each(function(){
var t = $(this);
if (!t.hasClass() || (t.hasClass("ms-completed") && !t.hasClass("active"))){
//if($(this).is('.ms-completed:not(.active)') || $(this).attr('class')==""){
var oldtxt = $(t).find('span a').text();
if(oldtxt == 'Order'){
t.find('span a').text("Ordered");
}else if(oldtxt == 'Booking'){
t.find('span a').text("Booked");
}else if(oldtxt == 'Receiving'){
t.find('span a').text("Received");
}else if(oldtxt == 'Loading'){
t.find('span a').text("Loaded");
}else if(oldtxt == 'Arrival'){
t.find('span a').text("Arrived");
}else if(oldtxt == 'Availability'){
t.find('span a').text("Available");
}else if(oldtxt == 'Delivery'){
t.find('span a').text("Delivered");
}else if(oldtxt == 'In transit'){
t.find('span a').text("Transited");
}else{
t.find('span a').text(oldtxt);
}
}
});
}
<a>
태그 텍스트를 <li>
공백이있는 ("")
클래스로 바꾸고 "ms-completed"
클래스 만있는 태그 텍스트로 바꿉니다. 현재 <li>
은 "MS-완료 활성 '클래스를 갖는 <a>
태그 텍스트를 대체
제안을