jQuery基于其类是“活动的"来加载一些东西. [英] jQuery load something based on whose class is "active"

查看:95
本文介绍了jQuery基于其类是“活动的"来加载一些东西.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将此选项卡与将ajax内容加载到div中的标签一起使用.我不能让它刷新间隔.顶部确实可以工作.

I'm trying to use this with tabs that load content with ajax into a div. I can't get it to refresh on the interval. The top part does work, however.

<script type="text/javascript">
 $(function rlAl() {
    if ($("#xicon1").hasClass("active")) {
    $("#actionlist").load("alcurrent.php");
    }
    else if ($("#xicon2").hasClass("active")) {
    alert("icon2");
    }
    else if ($("#xicon3").hasClass("active")) {
    alert("icon3");
    }
 });
 $(function() {
 setInterval(rlAl, 5000);
});
</script>

推荐答案

rlAl is undefined,因为它未附加到全局范围,请将其从您拥有的$()中取出,以便将其注册到window命名空间

rlAl is undefined because it wasn't attached to the global scope, take it out of the $() you have it in in order to register it in the window namespace

function rlAl() {
  if ($("#xicon1").hasClass("active")) {
    $("#actionlist").load("alcurrent.php");
  }
  else if ($("#xicon2").hasClass("active")) {
    alert("icon2");
  }
  else if ($("#xicon3").hasClass("active")) {
    alert("icon3");
  }
}
$(function() {
  rlAl(); // so it executes straight away on DOM ready
  setInterval(rlAl, 5000);
});

这篇关于jQuery基于其类是“活动的"来加载一些东西.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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