下拉菜单中的默认选择

下拉菜单中的默认选择

本文介绍了bootstrap 下拉菜单中的默认选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用引导程序下拉菜单,并且需要将第一个选项设为默认值.以下不起作用.

<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">选择功能<span class="caret"></span><ul class="dropdown-menu" aria-labelledby="dropdownMenu1"><li selected="selected"><a>特征 1</a></li><li><a>特征2</a></li><li><a>特征3</a></li><li><a>特征4</a></li><li><a>特征5</a></li><li><a>特征6</a></li>
解决方案

不幸的是,我认为您无法使用传统的引导下拉菜单实现这种效果.

与传统的 HTML选择"不同,引导下拉菜单通常用于将一系列链接分组到标题下.当您单击一个菜单项时,它不会被选中,而是通常会执行一个操作.

我建议只使用简单的 HTML 选择,但从引导 CSS 库中借用样式以使其看起来一致.类似的东西:

<option value="1" selected="selected">功能1</option><option value="2">功能2</option><option value="3">功能3</option><option value="4">功能4</option></选择>

I am using a bootstrap dropdown, and need to have the first option as default. The following doesn't work.

<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
    CHOOSE FEATURE
    <span class="caret"></span>
</button>

<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
    <li selected="selected"><a>Feature 1</a></li>
    <li><a>Feature 2</a></li>
    <li><a>Feature 3</a></li>
    <li><a>Feature 4</a></li>
    <li><a>Feature 5</a></li>
    <li><a>Feature 6</a></li>
</ul>
解决方案

Unfortunately, I don't believe you'll be able to achieve this effect using a conventional bootstrap drop down menu.

Unlike a traditional HTML "select", a bootstrap drop down is typically used to group a series of links under a header. When you click a menu item, it doesn't become selected as such, rather an action is usually performed.

I'd advise just using a straightforward HTML select, but borrowing styles from the bootstrap CSS library so it looks consistent. Something along the lines of:

<select class="bootstrap-select">
  <option value="1" selected="selected">Feature 1</option>
  <option value="2">Feature 2</option>
  <option value="3">Feature 3</option>
  <option value="4">Feature 4</option>
</select>

这篇关于bootstrap 下拉菜单中的默认选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:17