Weekday jQuery UI Tabs open on current day
I have weekday jQu开发者_Python百科ery UI tabs as follows which I want to open on the current weekday:
<div id="tabs">
<ul>
<li><a href="monday.php">Monday</a></li>
<li><a href="tuesday.php">Tuesday</a></li>
<li><a href="wednesday.php">Wednesday</a></li>
<li><a href="thursday.php">Thursday</a></li>
<li><a href="friday.php">Friday</a></li>
<li><a href="saturday.php">Saturday</a></li>
<li><a href="sunday.php">Sunday</a></li>
</ul>
<script type="text/javascript">
$(function() {
$( "#tabs" ).tabs({
ajaxOptions: {
error: function( xhr, status, index, anchor ) {
$( anchor.hash ).html(
"Couldn't load this tab. We'll try to fix this as soon as possible. " +
"If this wouldn't be a demo." );
}
}
});
});
</script>
I want the tabs to open on the current day of the week, I know something like this works:
.eq((new Date().getDay() || 7) - 1).click();
But can't get it to work and would appreciate some help. Also, I would like the tab for the current day to display the word 'Today' instead of the weekday.
I would appreciate some help.
Thanks,
Brendon
You can use the following to select
the tab matching the current day:
$('#tabs').tabs('select', ((new Date().getDay() || 7) - 1));
and you could modify the text of the active tab with the following:
$('#tabs .ui-state-active a').text('Today');
HTML
<div id="tabs">
<ul>
<li><a href="monday.php">Monday</a></li>
<li><a href="tuesday.php">Tuesday</a></li>
<li><a href="wednesday.php">Wednesday</a></li>
<li><a href="thursday.php">Thursday</a></li>
<li><a href="friday.php">Friday</a></li>
<li><a href="saturday.php">Saturday</a></li>
<li><a href="sunday.php">Sunday</a></li>
</ul>
</div>
JavaScript
$('#tabs').tabs();
$('#tabs').tabs('select', ((new Date().getDay() || 7) - 1));
$('#tabs .ui-state-active a').text('Today');
and needs the jQuery and jQuery UI libraries.
Demo
精彩评论