工作日 jQuery UI 选项卡在当天打开

发布于 2024-12-08 17:34:39 字数 1248 浏览 0 评论 0原文

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

<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>

我希望选项卡在本周的当天打开,我知道这样的方法可以工作:

.eq((new Date().getDay() || 7) - 1).click();

但无法让它工作,希望得到一些帮助。另外,我希望当天的选项卡显示“今天”一词,而不是工作日。

我希望得到一些帮助。

谢谢,

布伦登

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.

I would appreciate some help.

Thanks,

Brendon

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不羁少年 2024-12-15 17:34:39

您可以使用以下命令选择匹配的选项卡当前日期:

$('#tabs').tabs('select', ((new Date().getDay() || 7) - 1));

您可以使用以下内容修改活动选项卡的文本:

$('#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 库。

演示

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文