[英]Why setInterval is not working after auto tab change
I used JQuery .tab()
to built a tab , and I wanted to make it could be continuous auto switching tab , but it did't work after loaded the page.我使用JQuery .tab()
建立了一个tab ,我想让它可以连续自动切换tab ,但它在加载页面后不起作用。 I found out that when I imported this external script, the auto tab didn't work.我发现当我导入这个外部脚本时,自动选项卡不起作用。
<script type="text/javascript" src="/solar_energy/lib/jquery-1.9.1.min.js"></script>
Here is my code, please help me to know why it didn't work.这是我的代码,请帮助我知道为什么它不起作用。 Thx.谢谢。
var n = 3, //number of tabs i = 0; // current tab $("#tabs").tabs(); setInterval(function() { i = (++i < n ? i : 0); $("#tabs").tabs("option", "active", i); }, 2000);
<div id="tabs"> <ul> <li><a href="1.html">tab 1</a> </li> <li><a href="2.html">tab 2</a> </li> <li><a href="3.html">tab 3</a> </li> </ul> </div>
Your code work fine take a look at Working Fiddle , just make sure that your jquery-ui
is included correctly and check your console if there's an error.您的代码工作正常,请查看Working Fiddle ,只需确保正确包含您的jquery-ui
并检查您的控制台是否有错误。
HTML : HTML :
<div id="tabs">
<ul>
<li><a href="1.html">tab 1</a>
</li>
<li><a href="2.html">tab 2</a>
</li>
<li><a href="3.html">tab 3</a>
</li>
</ul>
</div>
JS : JS:
var n = 3, //number of tabs
i = 0; // current tab
$("#tabs").tabs();
setInterval(function() {
i = (++i < n ? i : 0);
$("#tabs").tabs("option", "active", i);
}, 2000);
If your code work without <script type="text/javascript" src="/solar_energy/lib/jquery-1.9.1.min.js"></script>
i guess that you're already included jquery somewhere in your code.如果您的代码在没有<script type="text/javascript" src="/solar_energy/lib/jquery-1.9.1.min.js"></script>
我猜您已经在代码中的某处包含了 jquery .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.