关于作者:
- 郑云飞, 程序员Java(web前端,web后端,oracle数据库or mysql数据库)
- 艺名:天放
- weibo:@tianFang
- blog: zhengyunfei.iteye.com
- email: zhengyunfei8@gmail.com
- 学习路线图
- 跟我一步一步学习bootstrap
这几天很忙,间隔了这么多天,今天周末了才腾出时间写博客。今天本来也没有时间的,要去加班,可是刚到公司,说是机房要停电整修。好吧,只好回家好好的睡了一觉,醒来就总结一下这几天工作中遇到的bootstrap的知识点吧。
首先说一说modal,如何弹出一个对话框,首先定义个对话框
<div class="modal hide fade" id=''myModal"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3>Modal header</h3> </div> <div class="modal-body"> <p>One fine body…</p> </div> <div class="modal-footer"> <a href="#" class="btn">Close</a> <a href="#" class="btn btn-primary">Save changes</a> </div> </div>
它有三个modal-header,modal-body和modal-footer组成,这是一个对话框的格式,那么如何弹出一个对话框呢?
比如定义一个按钮,当点击按钮的时候,触发弹出框事件。按钮格式如
<button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button> 只要将data-target的值和对话框的id值一样,点击对话框的时候,就会自动触发对话框事件,使其弹出来。 或者手动触发: $('#myModal').modal()
1、绑定事件,在关闭的时候,直接将数据清除:
- $("#model").on("hidden.bs.model",function(e){$(this).removeData();});
2、修改一下请求的url,添加随机参数,强制刷新,先用jQuery的get方法取内容,再放到modal中。如下:
- function remoteUrl(u){
- u += '&t=' + Math.random(1000)
- $.get(u, '', function(data){
- $('#remoteModal .modal-body').html(data)
- })
- $('#remoteModal').modal({show:true,backdrop:false})
- }
在一个问题就是datagrid表格的问题,不过我们工作中不是用的bootstrap的表格,而是用的
FuelUx的datagrid,首先我们定义一个datagrid
<table id="MyGrid" class="table table-bordered datagrid"> <thead> <tr> <th></th> </tr> </thead> <tfoot> <tr><th> <div class="datagrid-footer-left" style="display:none;"> </div> <div class="datagrid-footer-right" style="display:none;"> </div> </th> </tr></tfoot> </table>
Using datagrid
Call the datagrid via javascript:
- $('#MyGrid').datagrid({ dataSource: dataSource, stretchHeight:true})
Data Source
Provide a data source to the datagrid to supply column information and data. Your data source must support the following two methods.
columns | (none) | Returns an array of objects containing column information |
data | options (object), callback(function) | The options parameter contains search, sortProperty, sortDirection, pageIndex, and pageSize. Retrieve data then callcallback with an object containing data, start, end, count, pages, and page. View the source of this page for an example static data source. |
Methods
Fuel UX's datagrid exposes a method for reloading the grid.
reload | This method causes the datagrid to reload the data from the dataSource and return to the first page. |
clearSelectedItems | If row selection is enabled, this method will clear all rows currently selected. |
setSelectedItems | If row selection is enabled, this method will programmatically set specified rows within the datagrid by each element's primary key value. The argument passed to this method should be an array of string values. Note, this relies on the _data array being included in the DataSource as provided in the samples directory. |
getSelectedItems | If row selection is enabled, this method returns an object containing all the selected items within the datagrid. Each property in the returned object represents a selected value (by primary key) with the corresponding values being the selected data elements. |
$('#MyGrid').datagrid(columns: [{ property: 'payDate', label: '支付时间', sortable: true }, { property: 'amount', label: '支付金额', sortable: true } ],data:data: function(options, callback) { var url="<%=basePath%>/payment/search"; var param={"postpaidPlanId":postpaidPlanId}; $.ajax(url,{ dataType: 'JSON', data:param, type: 'post' }).done(function(res) { callback({ data: res.data, start: res.start, end: res.end, count: res.count, pages: res.pages, page: res.page }); }); } });
这样就可以初始化显示一个datagrid。
但是在工作中还要显示自定义列,那么如何在datagrid显示自定义列呢?
如下:
{ property: 'operation', label: '操作', render: function (item) { var html=''; if(item.payMode=='0') { html="<input type='button' class='btn btn-success' value='制定'/> <input type='button' class='btn btn-warning' value='修改'/>" + "<input type='button' class='btn btn-inverse' value='查看'/> "; }else{ html="<input type='button' class='btn btn-warning' value='修改'/>" + "<input type='button' class='btn btn-inverse' value='查看'/> "; } return html; }, sortable: true }
上面代码在datagrid中自定义一列显示button按钮。
此外我们还在datagrid中显示下拉列表:
{ property: 'select', label: '类型', render: function (item) { var html="<select id='myselect' > <option value='0'>次数</option> <option value='1'>比例</option> </select>" return html; }, sortable: true }
你想显示什么,就自定义html代码,显示就可以了。
3.另外一个遇到的问题就是动态添加一个表格,其中一个表格显示时间控件。
动态添加tr的方法如下:
//动态增加<tr/> $("#btn2").click(function(){ var html='<div class="datepicker-target"></div>'; var _len = $("#tab2 tr").length; var trhtml= "<tr align='center' id="+_len+">"+ " <td>"+html+"</td>" +"<td><input type='text' class='span2' name='money'/></td>" +"<td><button class='btn btn-danger' type='button' onclick='javascript:deltr("+_len+")' >删除</button></td></tr>" ; $("#tab2").append(trhtml); $('.datepicker-target').datepicker(); }) ;
刚开始时间控件显示出来了,但是无论如何也赋值不上,最后发现,原因是我动态添加的时候,时间控件赋值的id都一样了,所以赋值不了,最后解决方法,将id换成class属性,通过class属性显示时间控件
$('.datepicker-target').datepicker();
上一篇博客:bootstrap响应式布局 下一篇博客:
相关推荐
使用 Bootstrap-table表格进行分页,表格汇总统计,方便我们做报表
bootstrap框架使用中遇到的问题和解决方法。希望能够帮到更多人
对bootstrap常用的25个知识点进行了简单总结,附带总结文档与代码实例。总结文档月代码时一一对应的
bootstrap table各个属性值的详细说明,中文翻译版本。
最流行的前端CSS框架,bootstrap3.3.5中文手册,学习web前端的小伙伴一定不能错过,记住,坚持就是胜利,加油
bootstrap4中文离线手册
Bootstrap4中文整理版文档。收集整理的Bootstrap4文档,重新排版,支持目录索引。
Bootstrap3中文文档
bootstrap3 中文入门参考手册,bootstrap v3 中文文档
Bootstrap-中文(完整版)-API,它是chm格式极大提供了查找的方便。 个人感觉很好用。Bootstrap-中文(完整版)-API,它是chm格式极大提供了查找的方便。 个人感觉很好用
这个里面 包含整个bootstrap源程序 你所需要的都在了、里面.Bootstrap,来自 Twitter,是目前最受欢迎的前端框架。Bootstrap 是基于 HTML、CSS、JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷。 本教程将向您...
bootstrap3中文文档,文章整理自http://v3.bootcss.com
bootstrap-v3.3.5中文api手册,可随时随地离线查看,.chm文档
20131130 最新bootstrap3中文文档_cn 为了方便大家使用特别把资源分取消了.
bootstrap 3.3.4 中文文档 可用
Bootstrap3 中文文档 打不开请搜索 chm打开是空白页解决办法。
bootstrap3中文文档,
本手册总结了bootstrap官网上的基本知识,实在为bootstrap离线资源中的精华,关注bootstrap的童鞋赶紧下载吧!!! Bootstrap是Twitter推出的一个开源的用于前端开发的工具包。它由Twitter的设计师Mark Otto和Jacob...
bootstrap3.2.2 中文手册