twitter-bootstrap – 使用bootstrap将单选按钮设为必填字段

前端之家收集整理的这篇文章主要介绍了twitter-bootstrap – 使用bootstrap将单选按钮设为必填字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用bootstrap创建登录页面,这是我的代码
<form class="form-signin" action="firstLogin.action" method="post">
    <h2 class="form-signin-heading">Please sign in</h2>
    <input type="text" class="form-control" name="username" placeholder="User Name"     
       required="required" autofocus>
    <br>
    <input type="password" class="form-control" name="password" required="required" 
       placeholder="Password">
    <br>
    <div class="btn-group" data-toggle="buttons-radio">
   <button type="button" class="btn btn-primary" style="width: 150px">Admin</button>
   <button type="button" class="btn btn-primary" style="width: 150px">User</button> 
    </div>
   <div><br></div>

   <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
 </form>

我想将单选按钮字段设为必填字段.任何想法如何做到这一点.

解决方法

我知道了!

你需要做的就是

– 创建两个div,一个用于数据切换,另一个用于btn-group

因此,你会得到一组带收音机的按钮.设置那些无线电btns

class=”sr-only”

<form class="form-signin" action="firstLogin.action" method="post">
 <h2 class="form-signin-heading">Please sign in</h2>

<input type="text" class="form-control" name="username" placeholder="User Name" required autofocus>
<br>
<input type="password" class="form-control" name="password" required placeholder="Password">
<br>


                <div data-toggle="buttons">
                <div class="btn-group">

                    <label class="btn btn-primary">
                        <input type="radio" name="type" id="type" value="admin" class="sr-only" required>Admin
                    </label>
                    <label class="btn btn-primary">
                        <input type="radio" name="type" id="type" value="user" class="sr-only" required>User
                    </label>
                </div>
                </div>
            </div>

<br>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>

http://jsfiddle.net/nteb4/23/

它正在开发bootstrap3

猜你在找的Bootstrap相关文章