trigger jquery tabs by date

纵饮孤独 提交于 2020-02-03 02:12:56

问题


I am using jquery tabs to filter some events that are happening for one week. http://jqueryui.com/tabs/

So i have the tab

   <div id="tabs">
  <ul>
    <li><a href="#tabs-1">1st June 2013</a></li>
    <li><a href="#tabs-2">2nd June 2013</a></li>
    <li><a href="#tabs-3">3rd June 2013</a></li>
  </ul>
  <div id="tabs-1">
    <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris.</p>
  </div>
  <div id="tabs-2">
    <p>Morbi tincidunt</p>
  </div>
  <div id="tabs-3">
    <p>Mauris eleifend est et turpis.</p>
    <p>Duis cursus.</p>
  </div>
</div>

I want for example tab-1 to open on 1st June 2013 and then when the 2nd of june comes tab-2 will be the active tab on page load.


回答1:


You could use jQuery.now() to get the current date




回答2:


Kind of weird. You can do this way.

<li><a href="#tabs-1" data-date="2013-06-01">1st June 2013</a></li>
<li><a href="#tabs-2" data-date="2013-06-02">2nd June 2013</a></li>
<li><a href="#tabs-3" data-date="2013-06-03">3rd June 2013</a></li>

And once the page loads, you can use:

$(document).ready(function(){
    var today = (new Date()).getFullYear() + "-" + ((new Date()).getMonth()+1) + "-" + (new Date()).getDate();
    $('[data-date="' + today + '"]').click();
});

And you will get open the current day's tab.

Fiddle: http://jsfiddle.net/praveenscience/f2Mav/



来源:https://stackoverflow.com/questions/15297123/trigger-jquery-tabs-by-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!