jquery - 如何同时实现 bootstrap Tabs 和 Collapse menu?

标签 jquery html css twitter-bootstrap

我尝试实现 Bootstrap 选项卡和内部选项卡 BOOTSTRAP COLLAPSE。

对于标签,我实现了:

<script type="text/javascript">
$(document).ready(function()
 {  
//Redirecciona al tab, usando un prefijo al cargar por primera vez, al usar redirect en cake #_Pagos    
//Redirecciona al tab, usando #Pagos
/* Automagically jump on good tab based on anchor; for page reloads or links */
 if(location.hash) 
  {
     $('a[href=' + location.hash + ']').tab('show');         
  }


//Para evitar el bajar al nivel del tab, (al mostrarse el tab subimos)
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) 
{
    location.hash = $(e.target).attr('href').substr(1);
    scrollTo(0,0);      
});



//Actualiza el URL con el anchor o ancla del tab al darle clic
 /* Update hash based on tab, basically restores browser default behavior to
 fix bootstrap tabs */
$(document.body).on("click", "a[data-toggle]", function(event) 
  {
    location.hash = this.getAttribute("href");
  });


//Redirecciona al tab, al usar los botones de regresar y avanzar del navegador.
/* on history back activate the tab of the location hash if exists or the default tab if no hash exists */   
$(window).on('popstate', function() 
{
  //Si se accesa al menu, se regresa al tab del perfil (activo default), fixed conflict with menu
  //var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
  var anchor = location.hash;
  $('a[href=' + anchor + ']').tab('show');

});   

});//Fin OnReady
</script>

但是每当我点击 COLLAPSE 时,页面就会向上滚动。无论如何,我可以有效地使用两者。

这是链接:http://custmr.co.uk/industry-specific/

我们点击“不动产”后,就可以去崩溃了。

提前致谢

最佳答案

你错过了阻止“ anchor ”默认事件;

例如:

$(document.body).on("click", "a[data-toggle]", function(event){
    event.preventDefault();
    location.hash = this.getAttribute("href");
  });

仅供引用

http://api.jquery.com/event.preventdefault/

anchor 元素中的“事件点击”默认调用相同的页面,如<a href="#">some foo</a>

No se por que lo escribí en inglés si tus comentarios del código están en español。

关于jquery - 如何同时实现 bootstrap Tabs 和 Collapse menu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27336181/

相关文章:

jQuery Uncaught TypeError : object is not a function. WordPress $ 对象冲突?

javascript - jquery自定义过滤器不起作用

javascript - CSS - 即使 slider 设置为 100% 宽度,响应式推荐 slider 文本也不会调整大小

jquery - Bootstrap 中的自定义两行导航栏

javascript - IE 问题 : Gap between div & img

javascript - 获取 HTML 文档的宽度以随浏览器窗口调整大小

javascript - 单击停止连续的 jQuery each() 函数并添加事件类

html - 使用弹出菜单更新应用栏按钮

css - div 低于父 div (css)

javascript - 如何更改 chardin.js 中的文本颜色和样式