您的位置:首页 > Web前端 > BootStrap

bootstrap(警告框、按钮)

2015-08-05 17:33 721 查看
警告框(Alert)

样式文件:

LESS版本:源文件 alerts.less

警告框–结构与样式

<div class="alert alert-success" role="alert">
<button class="close"  data-dismiss="alert" type="button" >×</button>
<p>恭喜您操作成功!</p>
</div>


警告框–使用声明式触发警告框

击X会关闭整个警告框。

其实关闭按钮,不一定非要用X号,也可以是普通的按钮元素或者链接元素,只需要保证关闭元素带有自定义属性data-dismiss=”alert”即可,



<h3>使用a标签作为关闭按钮</h3>
<div class="alert alert-warning" role="alert">
<h4>谨防被骗</h4>
<p>请确认您转账的信息是你的亲朋好友,不要轻意相信不认识的人...</p>
<a href="#" class="btn btn-danger"  data-dismiss="alert">关闭</a>
</div>


警告框–JavaScript触发警告框

通过自定义data-dismiss=”alert”属性来触发警告框关闭之外,还可以通过JavaScript方法。只需要在关闭按钮上绑定一个事件

<div class="alert alert-warning" role="alert" id="myAlert">
<h4>谨防被骗</h4>
<p>请确认您转账的信息是你的亲朋好友,不要轻意相信不认识的人...</p>
<button type="button"  class="btnbtn-danger" id="close">关闭</button>
</div>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

<script>
$(function(){
$("#close").on("click",function(){
$(this).alert("close");
});
});
</script>


按钮插件(Button)

样式文件:

☑ LESS版本:源文件buttons.less

☑ 点击按钮时,按钮文字变为“正在加载…”,一旦加载完之后又变回“获取数据”。简单点说就是控制按钮状态,比如禁用状态、正在加载状态、正常状态等;

☑ 按钮切换状态

☑ 按钮模仿单选按钮

☑ 按钮模仿复选按钮

按钮插件–按钮加载状态

通过按钮可以设计状态提示,当单击按钮时,会显示loading状态信息。例如,点击“加载”按钮,会触发按钮的加载的状态

加载

通过data-loading-text属性定义加载的文本信息,然后通过JavaScript给按钮绑定一个事件,并给按钮添加一个button(“loading”)方法来激活按钮的加载状态行为。如下所示:

$(function(){
$("#loaddingBtn").click(function () {
$(this).button("loading");
});
});


按钮插件–模拟单选择按钮

在Bootstrap框架中按钮插件中,可以通过给按钮组自定义属性data-toggle=”buttons”

<div class="btn-group">
<label class="btn btn-primary">
<input type="radio" name="options" id="options1">男
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="options2">女
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="options3">未知
</label>
</div>
----------------------------------------------------------------------
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="radio" name="options" id="options1">男
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="options2">女
</label>
<label class="btn btn-primary">
<input type="radio" name="options" id="options3">未知
</label>
</div>


按钮插件–模拟复选按钮

<div class="btn-group">
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options1">电影
</label>
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options2">音乐
</label>
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options3">游戏
</label>
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options4">摄影
</label>
</div>
-------------------------------------------------------------------
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options1">电影
</label>
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options2">音乐
</label>
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options3">游戏
</label>
<label class="btn btn-primary">
<input type="checkbox" name="options" id="options4">摄影
</label>
</div>


按钮插件–按钮状态切换

使用 data-toggle 属性还可以激活按钮的行为状态,实现在激活和未激活之间进行状态切换。

<button type="button" data-toggle="button" class="btn btn-primary">确认</button>


按钮插件–JavaScript用法

1、切换按钮状态(得到焦点)

$("#mybutton").button("toggle")


2、重新恢复按钮:

$("#mybutton").button("reset")


3、任意参数:

$(“#mybutton”).button(“任意字符参数名”)

替换 data-任意字符参数名-text 的属性值为“按钮上显示的文本值”
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: