你好,我有一些divs叫archbar2,我想改变它使用.each循环,但我没有从JavaScript方面的反应。之前一切都在工作,因为警报效果很好。为什么我的班级没有改变?
jQuery(document).ready(function() {
var aktywator=0;
var punkty = 333;
if(punkty>=10 && punkty<300) aktywator = 0;
if(punkty>=300 && punkty<800) aktywator = 1;
if(punkty>=800 && punkty<2000) aktywator = 2;
if(punkty>=2000 && punkty<5000) aktywator = 3;
if(punkty>=5000 && punkty<10000) aktywator = 4;
if(punkty>=10000) aktywator = 5;
alert(aktywator);
$('.archbar2').each(function(id) {
if(aktywator==id)
{
alert("id=" + id + " aktywator=" + aktywator);
$(this).toggleClass("archbar");
}
})
});
.archbar
{
\t width: 50vw;
\t height: 13vw;
\t background-color: #1274B2;
\t text-align: center;
\t padding-top: 0.5vw;
\t margin-top: 2vw;
\t position: relative;
}
.archbar2
{
\t width: 50vw;
\t height: 13vw;
\t background-color: rgba(50,50,50,1);
\t text-align: center;
\t padding-top: 0.5vw;
\t margin-top: 2vw;
\t position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<center>
<div class="archbar2">
</div>
</center>
<center>
<div class="archbar2">
</div>
</center>
<center>
<div class="archbar2">
</div>
</center>
请看看下面这个例子,告诉我,为什么它不能正常运行。 Greatings
什么是你想要的结果? –
我想将类“archbar2”更改为“archbar”... $(this).toggleClass(“archbar”)不工作... – Artimal