| | |
| | | <link rel="stylesheet" href="src/css/layui.css">
|
| | | </head>
|
| | | <body>
|
| | | <div id="exp_container"></div>
|
| | | <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
|
| | | <script type="text/javascript" src="src/layui.js"></script>
|
| | | <script type="text/javascript" src="js/base.js"></script>
|
| | | <script type="text/javascript" src="pages/js/common.js"></script>
|
| | | <script>
|
| | | var ExpExcel = function() {
|
| | | this.thead = ''; // 表格的头部
|
| | |
| | | var prop = ExpExcel.prototype;
|
| | |
|
| | | // 初始化
|
| | | prop._init = function(ele, obj) {
|
| | | prop._init = function(obj) {
|
| | | var defaults = {
|
| | | thead: [],
|
| | | tbody: [],
|
| | |
| | | this.normal = opts.normal;
|
| | |
|
| | | this.form = this.initForm();
|
| | | this._setForm(ele);
|
| | | this._setForm();
|
| | | };
|
| | |
|
| | | // 设置页面中的元素
|
| | | prop._setForm = function(ele) {
|
| | | prop._setForm = function() {
|
| | | var ele = $('#exp_container');
|
| | | // 创建容器
|
| | | if(ele.length == 0) {
|
| | | $('body').append($('<div id="exp_container"></div>'));
|
| | | }
|
| | | ele = $('#exp_container');
|
| | | // 更新内容
|
| | | ele.text('');
|
| | |
|
| | |
| | |
|
| | | ele.append(form);
|
| | | this.form = form;
|
| | | }
|
| | | };
|
| | |
|
| | | // 设置表格头部的值
|
| | | prop._setThead = function(thead, pageBreak, dataBreak) {
|
| | |
| | | prop._setPageNames = function(pageNames, pageBreak) {
|
| | | var str = pageNames.join(pageBreak);
|
| | | this.pageNames = str;
|
| | | }
|
| | | };
|
| | |
|
| | | // 初始化form
|
| | | prop.initForm = function() {
|
| | | this.form = '12345';
|
| | | }
|
| | | };
|
| | |
|
| | | // 导出表格
|
| | | prop.xls = function(ele, obj) {
|
| | | prop.xls = function(obj) {
|
| | |
|
| | | this._init(ele, obj); // 初始化内容
|
| | | this._init(obj); // 初始化内容
|
| | | // 导出内容
|
| | | if(this.form == '12345') {
|
| | | alert('没有检测到form表单')
|
| | | }else {
|
| | | this.form.submit();
|
| | | }
|
| | | }
|
| | | };
|
| | |
|
| | | var expExcel = new ExpExcel();
|
| | |
|
| | | var tblData = {
|
| | | thead: [['h1', 'h2', 'h3', 'h4'], ['xh1', 'xh2', 'xh3', 'xh4']],
|
| | | tbody:[['t1', 't2', 't3', 't4'], ['xt1', 'xt2', 'xt3', 'xt3']]
|
| | | }
|
| | | };
|
| | |
|
| | | expExcel.xls($('#exp_container'), tblData);
|
| | | GLOBAL.expExcel.xls(tblData);
|
| | | </script>
|
| | | </body>
|
| | | </html> |