在bootstrap 3中使用onclick显示带外部链接的选项卡
我想链接到一个bootstrap 3.2.0选项卡,其链接如下:
Tab name
谢谢!!
这里有一个评论主题: https : //github.com/twbs/bootstrap/issues/2415 ,解决方案中的NONE工作顺利。
消息来源: http : //timforsythe.com/blog/hashtabs/
演示: https : //jsbin.com/quvelo/2/
此解决方案使用常规URL链接到外部,内部和任何位置的选项卡。
$(window).load(function() { // cache the id var navbox = $('.nav-tabs'); // activate tab on click navbox.on('click', 'a', function (e) { var $this = $(this); // prevent the Default behavior e.preventDefault(); // send the hash to the address bar window.location.hash = $this.attr('href'); // activate the clicked tab $this.tab('show'); }); // will show tab based on hash function refreshHash() { navbox.find('a[href="'+window.location.hash+'"]').tab('show'); } // show tab if hash changes in address bar $(window).bind('hashchange', refreshHash); // read has from address bar and show it if(window.location.hash) { // show tab on load refreshHash(); } });
你将bootsrap.js之后的这个js放在你调用工具提示或弹出窗口的函数中(例如)。 我在我的文档中的bootstrap.min.js之后加载了bootstrap-initializations.js文件。
用法:与用于链接锚点的用法相同:
Link