小编给大家分享一下BootStrap常用组件有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
<h4>图标</h4> <span class="glyphicon glyphicon-home"></span> <span class="glyphicon glyphicon-signal"></span> <span class="glyphicon glyphicon-cog"></span> <span class="glyphicon glyphicon-apple"></span> <span class="glyphicon glyphicon-trash"></span> <span class="glyphicon glyphicon-play-circle"></span> <span class="glyphicon glyphicon-headphones"></span>
<h4>按钮</h4> <button type="button" class="btn btn-default">按钮</button> <button type="button" class="btn btn-primary">primary</button> <button type="button" class="btn btn-success">success</button> <button type="button" class="btn btn-info">info</button> <button type="button" class="btn btn-warning">warning</button> <button type="button" class="btn btn-danger">danger</button>
<h4>按钮尺寸</h4> <button type="button" class="btn btn-default">按钮</button> <button type="button" class="btn btn-primary btn-lg">primary</button> <button type="button" class="btn btn-success btn-sm">success</button> <button type="button" class="btn btn-info btn-xs">info</button>
<h4>把图标显示在按钮里</h4> <button type="button" class="btn btn-default"><span class="glyphicon glyphicon-home"></span> 按钮</button>
<p class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> <span id="dropdown-title">菜单一</span> <span class="caret"></span> </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu1"> <li><a href="#" class="dropdown-item">菜单一</a></li> <li><a href="#" class="dropdown-item">菜单二</a></li> <li><a href="#" class="dropdown-item">菜单三</a></li> </ul> </p>
交互:监听每个菜单的点击事件,点击之后在title显示当前菜单
$('.dropdown-item').click(function () { $('#dropdown-title').text($(this).text()); });
<h4>输入框</h4> <p class="input-group"> <span class="glyphicon glyphicon-user"></span> <input type="text" placeholder="username"> </p> <p class="input-group"> <span class="glyphicon glyphicon-lock"></span> <input type="password" placeholder="password"> </p>
<h4>导航栏</h4> <nav class="navbar navbar-inverse navbar-fixed-top"> <p id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="#">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#contact">Contact</a></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="#">Action</a></li> <li><a href="#">Another action</a></li> <li class="pider"></li> <li class="dropdown-header">Nav header</li> <li><a href="#">Separated link</a></li> </ul> </li> </ul> </p><!--/.nav-collapse --> </p> </nav>
<h4>表单</h4> <form> <p class="form-group"> <span class="glyphicon glyphicon-user"></span> <input type="email" id="exampleInputEmail1" placeholder="Enter email"> </p> <p class="form-group"> <span class="glyphicon glyphicon-lock"></span> <input type="password" id="exampleInputPassword1" placeholder="Password"> </p> <p class="form-group"> <label for="exampleInputFile">File input</label> <input type="file" id="exampleInputFile"> <p class="help-block">Example block-level help text here.</p> </p> <p class="checkbox"> <label> <input type="checkbox"> Check me out </label> </p> <button type="submit" class="btn btn-default">Submit</button> </form>
<h4>警告框</h4> <p class="alert alert-warning alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> <strong>Warning!</strong> Better check yourself, you're not looking too good. </p> <p class="alert alert-success" role="alert"> <a href="#" class="alert-link">success!</a> </p> <p class="alert alert-info" role="alert"> <a href="#" class="alert-link">info!</a> </p> <p class="alert alert-warning" role="alert"> <a href="#" class="alert-link">warning!</a> </p> <p class="alert alert-danger" role="alert"> <a href="#" class="alert-link">danger!</a> </p>
<h4>进度条</h4> <p class="progress"> <p class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width: 60%;"> 70% </p> </p>
一般我们是用float:right来实现向右浮动的功能的,但是这里面右涉及了清除浮动、调整右边的margin、上下的margin等等问题,在bootstrap当然要用他的方法,只要添加一个class:pull-right就可以解决:
<span style="font-size: 30px;">item1</span> <p class="pull-right">item2</p>
这第一行是要跟第二行在一个水平线上的,所以第一行不能用<h2>之类的,因为这种元素自带换行功能。
tab可以方便的在一个页面里面切换显示的内容,bootstrap的tab使用非常简单:
<ul id="myTab" class="nav nav-tabs"> <li role="presentation" class="active"><a href="#tab1" data-toggle="tab">tab1</a></li> <li role="presentation"><a href="#tab2" data-toggle="tab">tab2</a></li> <li role="presentation"><a href="#tab3" data-toggle="tab">tab3</a></li> </ul> <span>这是宝贝管理页面</span> <p id="myTabContent" class="tab-content"> <p id="tab1" class="tab-pane active"> <p>这是tab1</p> </p> <p id="tab2" class="tab-pane"> <p>这是tab2</p> </p> <p id="tab3" class="tab-pane"> <p>这是tab3</p> </p> </p>
在js可以方便的捕捉tab的切换,并做出相应的改变,比如当第二个页面是加载一些数据,那么我等到切换到第二个页面我再去加载:
$('a[data-toggle="tab"]').on('shown.bs.tab',function (e) { var activeTab = $(e.target).text(); alert(activeTab); });
一个可以通过ajax请求json数据并生成表格的插件
项目地址:
https://github.com/wenzhixin/bootstrap-table
https://github.com/CodeSeven/toastr
http://www.ithao123.cn/content-2414918.html
在下载的文件里找到build文件夹,引入里面的toastr.min.js和toastr.css
此提示消息默认是显示在浏览器的右上角,我们可以在初始化里面改为顶部居中显示:
toastr.options.positionClass = 'toast-top-center';//显示位置
位置显示的设定有如下选项:
toast-top-right toast-botton-right toash-bottom-left toast-top-left toast-top-full-width 这个是在网页顶端,宽度铺满整个屏幕 toast-bottom-full-width toast-top-center顶端中间 toast-bottom-center
然后在我们需要显示的时候这样调用就行了:
toastr.success('提交数据成功'); toastr.error('Error'); toastr.warning('只能选择一行进行编辑'); toastr.info('info');
按钮:
<button class="btn btn-link"> 换个密码 </button>
js:
$('.btn').on('click',function () { $.post('xxx') .done(function (result) { var json = ajaxResultShow(result); if (json.result_code == 0) $('#pwdId').text(json.data1); }) .fail(function () { }) .always(function () { }); });
(1)此组件不属于bootstrap,他需要单独引入bootstrap-switch.min.js和bootstrap-switch.min.css;
(2)下载地址:http://www.bootcss.com/p/bootstrap-switch/
(3)使用方法:
添加框架:
<link href="bootstrap.css" rel="stylesheet"> <link href="bootstrap-switch.css" rel="stylesheet"> <script src="jquery.js"></script> <script src="bootstrap-switch.js"></script>
在html中添加组件:
<input type="checkbox" name="my-checkbox" checked>
在js中初始化:
$("[name='my-checkbox']").bootstrapSwitch();
可以在初始化中直接对状态进行设定:
$("#isOpenCheckbox").bootstrapSwitch('state',false);
切换状态:
$('#isOpenCheckbox').bootstrapSwitch('toggleState');
监听切换事件:
$('#isOpenCheckbox').on('switchChange.bootstrapSwitch', function (event,state) { alert(state);// true || false });
以上是“BootStrap常用组件有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。