我想在我的表单输入提交按钮上使用twitter引导图标。

http://twitter.github.com/bootstrap/base-css.html#icons上的例子主要是有样式的超链接。

我最接近的方法是让图标显示在按钮旁边,但不是在按钮里面。

<div class="input-prepend">
   <span class="add-on"><i class="icon-user icon-white"></i></span>
   <input type="submit" class="btn-primary" value="Login" >
</div>

当前回答

<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <button type="button" class="btn btn-info"> <span class="glyphicon glyphicon-search"></span> Search </button> </p> <a href="#" class="btn btn-success btn-lg"> <span class="glyphicon glyphicon-print"></span> Print </a> </p> </div> </body> </html>

其他回答

我认为你可以使用标签来达到这个目的。下面是一个推特引导HTML导航栏的示例:

<form class="navbar-search">
    <input type="text" class="search-query" placeholder="Search here" />        
    <label for="mySubmit" class="btn"><i class="icon-search icon-white"></i> Search me</label>
    <input id="mySubmit" type="submit" value="Go" class="hidden" />
</form>

基本上你得到一个标签元素的输入(type=submit),然后你隐藏实际的输入提交。用户可以单击label元素,但仍然可以完成表单提交。

有一种新的方法可以用bootstrap 3做到这一点:

<button type="button" class="btn btn-default btn-lg">
  <span class="glyphicon glyphicon-star"></span> Star
</button>

在bootstrap glyphicons页面的“如何使用”下面:

<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> </head> <body> <div class="container"> <button type="button" class="btn btn-info"> <span class="glyphicon glyphicon-search"></span> Search </button> </p> <a href="#" class="btn btn-success btn-lg"> <span class="glyphicon glyphicon-print"></span> Print </a> </p> </div> </body> </html>

您可以使用按钮标记代替输入

<button type="submit" class="btn btn-primary">
  <i class="icon-user icon-white"></i> Sign in
</button>

您可以在某处添加一个<a/>图标,并绑定一个JavaScrit动作 向它提交表单。类的名称和值(如有必要) 原始提交按钮的名称+值可以在一个隐藏属性中。这很简单 jQuery,请允许我避免纯JavaScript版本。

假设这是原始形式:

<form method="post" id="myFavoriteForm>
   ...other fields...
   <input class="btn btn-primary" type="submit" name="login" value="Let me in" />
</form>

这样修改:

<form method="post" id="myFavoriteForm">
   ...other fields...
   <a href="#" class="btn btn-primary" id="myFavoriteFormSubmitButton">
      <i class="icon-user icon-white"></i>&nbsp;Let me in
   </a>
</form>

...然后是神奇的jQuery:

$("#myFavoriteFormSubmitButton").bind('click', function(event) {
   $("#myFavoriteForm").submit();
});

或者如果你想确保用户总是能提交表单,那就是 换做是我,你可以把正常的提交按钮留在里面 并使用jQuery .hide()隐藏它。它确保登录仍然有效 无需JavaScript和jQuery按正常提交按钮(有 人们使用链接,w3m和类似的浏览器),但提供 如果可能的话,一个带有图标的花哨按钮。