jQuery addclass和toggle class未设置我的类
你好 出于某种原因,浏览器忽略了我的addClass和toggleClass jquery调用: HTML jQuery:jQuery addclass和toggle class未设置我的类,jquery,css,Jquery,Css,你好 出于某种原因,浏览器忽略了我的addClass和toggleClass jquery调用: HTML jQuery: 它起作用了。为什么不给我的类分配addClass和toggleclass命令?我的CSS中没有拼写错误。改为通过两门课程,我认为您没有引用jQuery库,或者您的文档准备就绪缺失: <script> $(function(){ // <-----------------------------you are missing this $('#
它起作用了。为什么不给我的类分配
addClass
和toggleclass
命令?我的CSS中没有拼写错误。改为通过两门课程,我认为您没有引用jQuery库
,或者您的文档准备就绪
缺失:
<script>
$(function(){ // <-----------------------------you are missing this
$('#homeNav').addClass('activeNavHome1');
if ($(window).width() < 1080) {
$('#homeNav').toggleClass('activeNavHome1 activeNavHome2');
}
});
</script>
$(函数(){//您是否已准备好调用它….?为什么javascripthomeNav
中的id在标记中似乎是Menuna
?如果您正在使用母版页,为什么不将其添加到母版页而不是index.aspx中?请在firebug中检查您的脚本..确保是否添加了该类..好吧,您的jQuery代码工作正常,class activeNavHome1总是被添加的,而activeNavHome2只有在窗口宽度小于1080时才被添加。您如何以及何时调用该代码?谢谢Jai-我正确引用了jquery,它位于文档就绪函数中。我的所有其他脚本都在工作……还有其他想法吗?
.activeNavHome1 {
background-position: -200px center;
}
.activeNavHome2{
background: url('/images/homeNavSmall.png') no-repeat left center;
background-position: -150px center;
}
$('#homeNav').addClass('activeNavHome1');
if ($(window).width() < 1080) {
$('#homeNav').toggleClass('activeNavHome2');
}
$('#homeNav').css('background-position', '-200px center')
<script>
$(function(){ // <-----------------------------you are missing this
$('#homeNav').addClass('activeNavHome1');
if ($(window).width() < 1080) {
$('#homeNav').toggleClass('activeNavHome1 activeNavHome2');
}
});
</script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>