Javascript 今天更改UL背景
我有一个简单的课程日历,如果是一周中的那一天,我希望day列有所不同 例如,如果是星期三,则星期三列不同 我一直在玩,但没有用,并通过论坛搜索。我已经说到这一点了 我愿意接受任何新方法。谢谢 脚本Javascript 今天更改UL背景,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我有一个简单的课程日历,如果是一周中的那一天,我希望day列有所不同 例如,如果是星期三,则星期三列不同 我一直在玩,但没有用,并通过论坛搜索。我已经说到这一点了 我愿意接受任何新方法。谢谢 脚本 <script src="http://code.jquery.com/jquery-1.7.1.js" type="text/javascript"></script> <script> $('.fc-today').prevAll('ul').css('bac
<script src="http://code.jquery.com/jquery-1.7.1.js" type="text/javascript"></script>
<script>
$('.fc-today').prevAll('ul').css('backgroundColor','yellow');
$('.fc-today').parent().prevAll().find('ul').css('backgroundColor','yellow');
</script>
大概是这样的:
JS
div.calendar-daycontent {
float : left ;
width : 138px ;
margin : 1px ;
display : block ;
}
div.calendar-daycontent ul {
float : left ;
width : 100% ;
display : block ;
margin-bottom : 2px ;
}
.fc-mon ul {background-color:Red;}
.fc-tue ul {background-color:green;}
.fc-wed ul {background-color:blue;}
.fc-thu ul {background-color:Red;}
.fc-fri ul {background-color:Red;}
.fc-sat ul {background-color:green;}
.fc-sun ul {background-color:blue;}
.fc-today ul {}
div.calendar-daycontent ul a:link, div.calendar-daycontent ul a:visited {
float : left ;
width : 122px ;
display : block ;
padding : 12px 8px ;
text-decoration : none ;
}
div.calendar-daycontent ul a:hover {
float : left ;
width : 122px ;
display : block ;
padding : 12px 8px ;
text-decoration : none ;
background-color : #6bb925 ;
-o-transition : .3s ;
-ms-transition : .3s ;
-moz-transition : .3s ;
-webkit-transition : .3s;
transition : .3s ;
}
div.calendar-daycontent ul li {
float : left ;
width : 100% ;
display : block ;
padding : 2px 0px ;
color : #151515 ;
text-align : center ;
}
div.calendar-daycontent ul li.class-header {
font-size : 15px ;
font-weight : 800 ;
text-transform : uppercase ;
font-style : italic;
color : #6bb925 ;
margin-top : 2px ;
margin-bottom : 1px ;
}
div.calendar-daycontent ul:hover li.class-header {
color : #fff ;
}
div.calendar-daycontent ul li.class-inst {
font-size : 12px ;
font-weight : 800 ;
}
div.calendar-daycontent ul li.class-time {
font-size : 11px ;
font-weight : 800 ;
}
div.calendar-daycontent ul li.class-room {
font-size : 11px ;
}
$(function() {
var dayOfWeek = (new Date).getDay();
var dayClasses = ['fc-sun', 'fc-mon', 'fc-tue', 'fc-wed', 'fc-thu', 'fc-fri', 'fc-sat'];
$('.' + dayClasses[dayOfWeek] + ' ul').css('backgroundColor', 'yellow');
});
尝试使用
Date
获取一周中的当前日期:
$(function(){
var day = new Date().getDay();
day = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"][day];
$('div.calendar-daycontent.fc-' + day + ' ul').css({'background':'yellow'});
});
锚点不能是无序列表的子元素,您应该将其移出。谢谢。。我可以看出小提琴是有效的,但当我把它放进编辑器并测试它时,它就不起作用了。这是我的部分,对吗?window.jQuery | | document.write(“”)var dayOfWeek=(新日期).getDay();var dayClasses=['fc-sun','fc-mon','fc-tue','fc-wed','fc-thu','fc-fri','fc-sat']$('.'.+dayClasses[dayOfWeek]+'ul').css('backgroundColor','yellow');不需要这一行
window.jQuery | | document.write(“”)
,因为您已经在头部添加了jQuery。另外,将我的代码包装在jQuery的ready
事件处理程序中。此外,我更新了我的答案以反映这一点。此外,正如pete在评论中建议的那样,您应该将a
标记移动到li
标记内部。谢谢您。我可以看到它在fiddle中工作,但当我将它移动到我的文件时,它就不工作了。你有什么建议吗?Thanks@Lozano,请检查jQuery导入
$(function(){
var day = new Date().getDay();
day = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"][day];
$('div.calendar-daycontent.fc-' + day + ' ul').css({'background':'yellow'});
});