问题描述:

Simple question; I want to highlight some text if it is monday, some other when it's tuesday etc.

$('p.day:eq("' + new Date().getDay() + '")').addClass('today');

I feel like I'm so close.

jsFiddle.

网友答案:

you should do :

$('p.day').eq(new Date().getDay()-1).addClass('today');
网友答案:
$('p.day:eq(' + new Date().getDay() + ')').addClass('today');

You need to take out the quotes in the :eq() - pass the value as an integer, not a string.

Also, using .getDay(), Sunday is day number 0, so you'll either need to change the order of your days, or create another work-around for this.

网友答案:
$('p.day').eq(new Date().getDay()).addClass('today');

Fixed DEMO

Or using the :eq psudo css selector:

$('p.day:eq(' + new Date().getDay() + ')').addClass('today');

The number should be a number and not a string.

相关阅读:
Top