Ruby on rails 链接到rails中的特定ajax选项卡
我有一个问题还没有找到答案 在Rails 4应用程序中,我使用ajax选项卡。下面是代码设置的示例 show.html.erbRuby on rails 链接到rails中的特定ajax选项卡,ruby-on-rails,ajax,url,hyperlink,tabs,Ruby On Rails,Ajax,Url,Hyperlink,Tabs,我有一个问题还没有找到答案 在Rails 4应用程序中,我使用ajax选项卡。下面是代码设置的示例 show.html.erb <div id="ajaxtabs"> <ul class="nav nav-tabs"> <li><%= link_to 'Members', some_member_path, :remote => true %></li> <li><%= link_to 'Ho
<div id="ajaxtabs">
<ul class="nav nav-tabs">
<li><%= link_to 'Members', some_member_path, :remote => true %></li>
<li><%= link_to 'Hosts', some_host_path, :remote => true %></li>
</ul>
</div>
<div class="tab-content">
<div id="tab-display"></div>
</div>
一切都很好地工作,但有一个功能,我想开始工作,那就是能够链接到一个特定的标签
例如,如果我想链接到“成员”选项卡,我可以键入url,可能是这样的?
sitename.com/groups/#members选项卡您可以尝试以下方法
在
members.js.erb
的$(“#tab display”).html(“”)下面
您需要添加window.location.href=window.location.href+'#成员选项卡'#成员选项卡'
是选项卡名称的值。看起来您正在使用css类名引导。如果是这种情况,那么您可以调用选项卡
函数在页面加载时更改为右侧选项卡
window.location.href= window.location.href + '#members-tab'
假设您有如下javascript:
<script type="text/javascript">
$(function() {
var hash = document.location.hash;
if (hash) {
$('.nav-tabs a[href='+hash+']').tab('show');
}
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
window.location.hash = e.target.hash;
});
});
</script>
$(函数(){
var hash=document.location.hash;
if(散列){
$('.nav tabs a[href='+hash+']').tab('show');
}
$('a[data toggle=“tab”]”)on('show.bs.tab',函数(e){
window.location.hash=e.target.hash;
});
});
这非常简单——它从URL获取参数,并希望它与选项卡ID匹配。请注意,如果页面上有多个可以使用特殊URL的内容,则可能会发生JS错误。单击选项卡时,它会在URL中添加“成员”选项卡。但除此之外什么都不做。谢谢。它引导我找到一个检查散列的解决方案,然后单击();在具有相同id的相关选项卡上。 window.location.href= window.location.href + '#members-tab'
<script type="text/javascript">
$(function() {
var hash = document.location.hash;
if (hash) {
$('.nav-tabs a[href='+hash+']').tab('show');
}
$('a[data-toggle="tab"]').on('show.bs.tab', function (e) {
window.location.hash = e.target.hash;
});
});
</script>