【发布时间】:2017-12-09 00:03:31
【问题描述】:
我的页面有两个标签;其中一个随机将处于活动状态,默认情况下将加载其日期。第二个选项卡将处于非活动状态,直到用户单击它,然后它将使用 Ajax 加载内容。 (尚未加载)
我需要做的就是在两个选项卡中触发此代码:
$('#listings').attr('class', 'mobile row');
但我无法让它在非活动选项卡中运行,因为 JQuery 总是在 Ajax 完成加载之前停止。
这是标签页的 HTML 代码:
<ul class="tabs tabs-hash">
<li class="" id="tab_listings" lang="listings">
<a href="#listings" data-target="listings">Property</a>
</li>
<li class="active" id="tab_automobile" lang="automobile">
<a href="#automobile" data-target="automobile">Vehicles</a>
</li>
</ul>
这是点击每个选项卡时显示的内容:
标签#1(活动)
<div class="tab_area" id="area_automobile" style="display: block;">
<section id="listings" class="mobile row">
some content here
</section>
</div>
标签#2(非活动)
<div class="tab_area hide" id="area_listings" style="display: none;">
<span class="text-notice">**Loading...** </span><!-- This span is loading content using Ajax and JQuery finish before its complete and this content will have new section with the target class need to be changed by Jquery -->
</div>
一旦 Inactive 选项卡变为 Active 并且 Ajax 完成加载
此部分将出现,class="mobile row" 需要更改
<section id="listings" class="mobile row">
some content here
</section>
我尝试搜索 Stack Overflow,但我找到的所有帖子都没有解决我的问题。
有人可以解释实现目标的方法吗?
【问题讨论】:
-
第二个标签有单独的id吗?
-
什么是
#listings?选项卡 ID 还是元素? -
@Carl Edwards 谢谢,我用标签页 HTML 代码更新了帖子。
-
@Colin Cline #listing 是我需要更改其类的其他 div。及其非活动/活动选项卡的一部分......它是网格/列表视图......当您单击每个选项卡时,它将调用它的视图
-
这对你不起作用? Tbh 我对你想在这里实现的目标有点困惑
$('#listings', '#automobile').attr('class', 'mobile row');
标签: javascript jquery dom jquery-events mutation-observers