Bootstrap选项卡没有锚?(Bootstrap tabs without anchors?)

系统教程 行业动态 更新时间:2024-06-14 16:57:17
Bootstrap选项卡没有锚?(Bootstrap tabs without anchors?)

我想知道是否可以在不使用锚元素<a>情况下编写Bootstrap选项卡?

我想知道的原因是,我想添加标签中的<a>无效的孩子 - 在我的情况下,我想添加一个<input> (注意<input>不用于控制选项卡, 因此)。

原型选项卡示例可能是:

<div class="tabbable"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li> <li><a href="#tab2" data-toggle="tab">Section 2</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab1"> <p>I'm in Section 1.</p> </div> <div class="tab-pane" id="tab2"> <p>I'm in Section 2.</p> </div> </div> </div>

我知道我可以让选项卡以编程方式显示使用:

$('#tab1').tab('show')

但这似乎取决于它是<a>的事实。 例如,我可以使用一个<div> ,并使用JQuery钩入click事件?

我需要某种方式来指定href如果我这样做。

I wonder whether it is possible to write Bootstrap tabs without using anchor elements <a>?

The reason I want to know is that I want to add elements inside the tab that are not valid children of <a> - in my case I want to add an <input> (note the <input> is not used to control the tabs, as such).

An archetype tab example may be:

<div class="tabbable"> <ul class="nav nav-tabs"> <li class="active"><a href="#tab1" data-toggle="tab">Section 1</a></li> <li><a href="#tab2" data-toggle="tab">Section 2</a></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab1"> <p>I'm in Section 1.</p> </div> <div class="tab-pane" id="tab2"> <p>I'm in Section 2.</p> </div> </div> </div>

I know I can make tabs show programmatically using:

$('#tab1').tab('show')

But that appears to depend on the fact that it's an <a>. Could I use a <div>, for example, and hook into the click event with JQuery?

I would need some way to specify the href if I were to do it that way.

最满意答案

您可以使用任何其他元素。 使用data-target代替href属性。

<div class="tabbable"> <ul class="nav nav-tabs"> <li class="active"><span data-target="#tab1" data-toggle="tab">Section 1</span ></li> <li> <span data-target="#tab2" data-toggle="tab">Section 2</span ></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab1"> <p>I'm in Section 1.</p> </div> <div class="tab-pane" id="tab2"> <p>I'm in Section 2.</p> </div> </div> </div>

不需要自定义JavaScript,但你需要风格。 jsfiddle中的示例 。

You can use any other element. Instead of href attribute, use data-target.

<div class="tabbable"> <ul class="nav nav-tabs"> <li class="active"><span data-target="#tab1" data-toggle="tab">Section 1</span ></li> <li> <span data-target="#tab2" data-toggle="tab">Section 2</span ></li> </ul> <div class="tab-content"> <div class="tab-pane active" id="tab1"> <p>I'm in Section 1.</p> </div> <div class="tab-pane" id="tab2"> <p>I'm in Section 2.</p> </div> </div> </div>

No need for custom javascript, but you need to style. Example in jsfiddle.

更多推荐

本文发布于:2023-04-12 19:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/754b2599c74de08c0af6bcb5170ccc27.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   Bootstrap   anchors   tabs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!