codecamp

Bootstrap 单选按钮

你可以创建一组单选按钮,其中仅一个按钮是可选的。

<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript"
  src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<link rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet"
  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script
  src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script
  src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">


</script>  
</head>
  <body style="margin:30px">
    <div class="btn-group" data-toggle="buttons">
        <label  class="btn btn-info">
            <input  type="radio" name="options"> Option  1
        </label>
        <label  class="btn btn-info">
            <input  type="radio" name="options"> Option  2
        </label>
        <label  class="btn btn-info">
            <input  type="radio" name="options"> Option  3
        </label>
    </div>
  </body>
</html>

预选

将input的标签元素上添加类.active以预选一个选项。

<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<style type="text/css">
    .bs-example{
      margin: 20px;
    }
</style>
</head>
<body>
<div class="bs-example">
    <div class="btn-group" data-toggle="buttons">
        <label class="btn btn-primary active">
            <input type="radio" name="options" id="option1"> Option 1
        </label>
        <label class="btn btn-primary">
            <input type="radio" name="options" id="option2"> Option 2
        </label>
        <label class="btn btn-primary">
            <input type="radio" name="options" id="option3"> Option 3
        </label>
    </div>
</div>
</body>
</html>

Bootstrap 表单验证
Bootstrap Accordion插件
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Bootstrap 介绍

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }