2016-01-07 19 views
11

hình thức của tôi hiện chứa mã này:Với Bootstrap, làm cách nào để hiển thị đầu vào radio dưới dạng nút?

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> 
 
<label for="opt-0"><input type="radio" name="opt" id="opt-0" checked>Option 0</label> 
 
<label for="opt-1"><input type="radio" name="opt" id="opt-1">Option 1</label> 
 
<label for="opt-2"><input type="radio" name="opt" id="opt-2">Option 2</label>

Thay vì hiển thị các nút radio như nút radio, tôi muốn làm cho họ trông giống như nút thường xuyên, như thế này:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> 
 
<button class="btn btn-primary">Option 0</button> 
 
<button class="btn btn-default">Option 1</button> 
 
<button class="btn btn-default">Option 2</button>

Tôi có radio và tôi muốn làm cho chúng trông giống như các nút bấm được. Làm thế nào tôi phải làm điều đó với Bootstrap?

Trả lời

34
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>  
<div class="btn-group" data-toggle="buttons"> 
     <label class="btn btn-primary"> 
     <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> 
+0

Điều này tiết kiệm thời gian của tôi !!!! - Thay thế thẻ cũ

+0

@Shibu Thomas, Có thể hiển thị menu phụ thả xuống trong bootstrap 3 không? – Keynes

+0

@Keynes Bạn có thể tham khảo https://www.w3schools.com/bootstrap/bootstrap_dropdowns.asp –

0

Bạn có thể thử xem các nhóm nút, đây là một goup của - các nút tốt ... có thể chuyển đổi thành một nút vô tuyến.

JSFiddle

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
<script src="https://code.jquery.com/jquery.js"></script> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/js/bootstrap.min.js"></script> 

<div class="btn-group" role="group" aria-label="..."> 
    <button type="button" class="btn btn-primary">Left</button> 
    <button type="button" class="btn btn-primary">Middle</button> 
    <button type="button" class="btn btn-primary">Right</button> 
</div> 

Hope this helps!

+0

Điều này có thể làm việc, nhưng: 1. nếu tôi bấm vào một nút, nó không vẫn được lựa chọn; 2. không có các phần tử '' và tôi không thể gửi biểu mẫu – Likk

2
<div class="btn-group" data-toggle="buttons"> 
    <label class="btn btn-primary active"> 
    <input type="checkbox" autocomplete="off" checked> Checkbox 1 (pre-checked) 
    </label> 
    <label class="btn btn-primary"> 
    <input type="checkbox" autocomplete="off"> Checkbox 2 
    </label> 
    <label class="btn btn-primary"> 
    <input type="checkbox" autocomplete="off"> Checkbox 3 
    </label> 
</div> 

jsfiddle-link
getbootstrap

Các vấn đề liên quan