【问题标题】:Bootstrap input-group textarea with button带按钮的引导输入组文本区域
【发布时间】:2014-08-24 19:42:11
【问题描述】:

我正在尝试实现一个简单的提交输入组。我目前有以下内容:

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>

<div class="input-group">
    <textarea class="form-control custom-control" rows="3" style="resize:none"></textarea> <span class="input-group-btn">
                                    <button class="btn btn-primary">                            
                                        <span>Send</span>

    </button>
    </span>
</div>

我希望“发送”按钮占据整个文本区域的高度。这可行吗?

【问题讨论】:

  • 不要错过你的 ">" 结束语:style="resize:none">

标签: html twitter-bootstrap


【解决方案1】:

您需要做的是使用input-group-addon 实用程序。这将允许按钮的空间占据整个高度。您将需要调整填充,因为它仅适用于悬停(颜色变化)。我建议复制所有相关的类样式并自己制作(对于颜色和背景颜色,因此它不是默认的 Bootstrap 样式)。

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>

<div class="input-group">
    <textarea class="form-control custom-control" rows="3" style="resize:none"></textarea>     
    <span class="input-group-addon btn btn-primary">Send</span>
</div>

我知道它不符合 Bootstrap 文档,但他们的文档假设您没有使用 textarea。

【讨论】:

  • 我不能更改按钮大小吗?
  • @Aibrean 您应该将引导链接更改为 https。最新版本的 Chrome 会阻止 https 网站上的 http 内容。
  • 还将 tabindex="0" 添加到 span 标签以便能够使用键盘导航。喜欢:发送
【解决方案2】:

只是为了详细说明 Aibrean 的回答,并进一步阐明如何使他/她的span 标签可操作。

我们需要将 span 绑定到一个事件监听器,在下面的示例中我使用 jQuery。

; (function ($) {
  $('#submitMyForm').on('click', function () {
    //$('#myForm').submit(); // js fiddle won't allow this
    alert("form submitted");
  });
  
})(jQuery)
#exampleWrapper {
  padding: 100px;
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>

<div id="exampleWrapper">
  <form id="myForm" method="POST" action="?process-form">
      <div class="input-group">
          <textarea class="form-control custom-control" rows="3" style="resize:none"></textarea>
          <span class="input-group-addon btn btn-primary" id="submitMyForm">Send</span>
      </div>
  </form>
</div>

【讨论】:

    【解决方案3】:

    假设我们要创建一个文本区域,左边(开始处)有一个 GO 按钮,右边(结束处)有一个搜索符号。 这是使用引导程序执行此操作的代码

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
    Creating a button in text area using bootstrap        
    </title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <style>
    
    </style>
    </head>
    <body>
    <div class="container-fluid">
    
    
    <label for="search" class="sr-only">Search</label>
    <input type="text" id="search" class="form-control" placeholder="Search">
    <span class="glyphicon glyphicon-search form-control-feedback"></span>
    
    
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js">
    </script>
    <script src="js/bootstrap.min.js">
    </script>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2015-06-13
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      • 1970-01-01
      相关资源
      最近更新 更多