2014-11-27 4 views
0

Мне не удалось получить значение, которое класс span щелкнул в jquery. при условии, если значение равно двум значениям sinn sapn. например if (span value == this) {} else {} Мне нужно значение span в функции jquery. это мой код:принять значение класса span в jquery

<div class="two toggle_height"> 
    <h6 style="padding: 0 171px;">Is Active</h6> 
    <div class="button-wrap button-active"> 
     <div class="button-bg"> 
     <div class="button-out"><span class="out">OFF</span></div> 
     <div class="button-in"><span>ON</span></div> 
     <div class="button-switch"></div> 
     </div> 
    </div> 
    </div> 
Jquery: 


    $('.button-wrap').on("click", function(){ 
    $(this).toggleClass('button-active'); 
    }); 

$('.button-wrap').on("click", function(){ 
 
    
 
    $(this).toggleClass('button-active'); 
 
    
 
});
.two .button-wrap { 
 
width: 113px; 
 
margin: 7px auto 0; 
 
cursor: pointer; 
 
padding: 1px; 
 
} 
 
.two .button-bg { 
 
width: 100%; 
 
background-color: #ddd; 
 
border-radius: 0px; 
 
padding: 2px 0px; 
 
color: #fff; 
 
---------- 
 
transition: all 0.2s ease; 
 
} 
 
.two .button-active .button-bg { 
 
background-color: #22dd22; 
 
} 
 
.two .button-switch { 
 
position: relative; 
 
left: 0px; 
 
width: 37px; 
 
height: 16px; 
 
border: solid 5px; 
 
border-radius: 0px; 
 
transition: all 0.2s ease; 
 
margin-top: 1px; 
 
text-align: center; 
 
margin-left: 1px; 
 
} 
 
.two .button-active .button-switch { 
 
left: 62px; 
 
} 
 
.two .button-in, 
 
.two .button-out { 
 
position: absolute; 
 
transition: all 0.2s ease; 
 
padding-top: 4px; 
 
font-size: 0.8em; 
 
text-transform: uppercase; 
 
font-weight: bold; 
 
padding-left: 4px; 
 
} 
 
.two .button-in { 
 
margin-left: 75px; 
 
} 
 
.two .button-out { 
 
margin-left: 18px; 
 
color: #dd2222; 
 
} 
 
.two .button-active .button-out { 
 
color: #fff; 
 
} 
 
.two .button-active .button-in { 
 
color: #22dd22; 
 
} 
 
.two .button-active .button-bg { 
 
background-color: #000; 
 
} 
 
/*............. 
 
btn closed 
 
.............*/ 
 
.out{ 
 
margin-left: -7px; 
 
} 
 
.all_btns{ 
 
/* [disabled]float:right; */ 
 
} 
 
.upload_img{ 
 
margin-left: -3px; 
 
} 
 
.footer_botm{ 
 
margin-bottom: -19px; 
 
} 
 
.footer_botm{ 
 
margin-bottom: -19px; 
 
background-color: rgba(232, 219, 219, 0.4); 
 
border-radius: 6px; 
 
} 
 
.choose_efil{ 
 
margin-left: 4px !important; 
 
} 
 
element.style { 
 
} 
 
.total_footer.title { 
 
margin-top: 11px; 
 
padding: 5px; 
 
width: 98%; 
 
margin-bottom: -30px; 
 
} 
 
.txt_label{ 
 
margin-left: -12px !important; 
 
} 
 
.two { 
 
margin-left: 7px; 
 
margin-top: -29px; 
 
} 
 
.module_toggle{ 
 
margin-top: -13px !important; 
 
margin-left: -36px !important; 
 
}
<div class="two toggle_height"> 
 
           <h6 style="padding: 0 171px;">Is Active</h6> 
 
            <div class="button-wrap button-active"> 
 
             <div class="button-bg"> 
 
              <div class="button-out"><span class="out">OFF</span></div> 
 
              <div class="button-in"><span>ON</span></div> 
 
              <div class="button-switch"></div> 
 
              
 
               
 
             </div> 
 
            </div> 
 
          </div>

+3

Где ваш код jQuery, это только разметка? – ummahusla

+0

напишите свой код jquery. – Haris

+0

$ ('. Button-wrap'). On ("click", function() { $ (this) .toggleClass ('button-active'); }); – BlackBird

ответ

0
$(".out").on("click", function() 
{ 
    alert($(".out").html()) // alerts OFF 
}) 
+1

** alert ($ ('. Out'). Html()) ** – Aditya

+0

Спасибо за исправление Aditya. Обновлен мой ответ – Bhaskara

0

Вы можете попробовать:

$('.button-in span').text() или $('.button-in span').html()

JQuery API

Смежные вопросы