工作日 jQuery UI 选项卡在当天打开 [英] Weekday jQuery UI Tabs open on current day

查看:13
本文介绍了工作日 jQuery UI 选项卡在当天打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下工作日 jQuery UI 选项卡,我想在当前工作日打开:

I have weekday jQuery 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.

我将不胜感激.

谢谢,

布兰登

推荐答案

你可以使用下面的选择与当天匹配的标签:

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');

并且需要 jQuery 和 jQuery UI 库.

and needs the jQuery and jQuery UI libraries.

演示

这篇关于工作日 jQuery UI 选项卡在当天打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆