BootStrap 智能表单系列 二 BootStrap支持的类型简介
代码如下(链接地址:https://github.com/xiexingen/Bootstrap-SmartForm/blob/master/demo/form1-basic.html):
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>基础配置</title> <link rel="stylesheet" href="../css/bootstrap.css"> <script src="../lib/jquery.js"></script> <script src="../lib/bootstrap.js"></script> <!--工具方法--> <script src="../scripts/global.js"></script> <!--插件--> <script src="../scripts/plugin.js"></script> </head> <body> <div class="panel panel-default"> <div class="panel-heading"><label>基础配置</label></div> <div class="panel-body"> <form action="#" id="formContainer" class="form form-horizontal"></form> </div> </div> <div class="panel panel-default"> <div class="panel-heading"><label>介绍</label></div> <div class="panel-body"> <h3>支持的表单元素包括:text、select、radio、checkbox、datetime、search、textarea、自定义</h3> </div> </div> <script> $(function () { var eles=[ {ele:{type:'text',name:'UserName',title:'用户名:'}}, [ {ele:{type:'radio',name:'sex',title:'性别:',items:[{text:'男',value:1},{text:'女',value:2}]}}, {ele:{type:'checkbox', name:'plant',title:'使用平台:',items:[{text:'APP',value:'app'},{text:'web',value:'web'}]}}, ], {ele:{type:'select',name:'province',title:'省份:',withNull:true,items:[{text:'广东',value:'GD'},{text:'湖南',value:'HN'}]}}, {ele:{type:'datetime',name:'FromeDate',title:'有效期:'}}, {ele:{type:'search',name:'selectName',title:'选择:'}}, {ele:{type:'textarea',name:'address',title:'地址:'}}, {ele:{pre:{text:'<input type="radio" />'},type:'text',name:'pre',title:'叉前面:'}}, {ele:{next:{text:'<input type="radio" />'},type:'text',name:'next',title:'叉后面:'}}, {ele:{pre:{text:'<input type="checkbox" />'},next:{text:'$'},type:'text',name:'pre&next',title:'前后皆叉:'}}, ]; //隐藏表单元素主要用于编辑时候后台可以区别开来 var hides = [{ id: 'GUID' }]; var bsForm = new BSForm({ eles: eles, hides: hides, autoLayout:true }).Render('formContainer'); }); </script> </body></html>
主要是下面的js那一块,通过该段js生成form表单
运行效果图:
得到如图所示的结果