bootstrapTable printThis打印插件 中 printThis.js中的一个buge

printThis打印插件还有一个大坑,先看看,一定要注意:

如果你用的开发工具(HBuilder.exe)访问形式是ip的形式如:http://127.0.0.1:8020/TestBootStrap11/index.html;打印的时候带数据样式,

但是,如果你在本地打开index.html,访问地址:file:///E:/EhtmlWorking/TestBootStrap11/index.html,再去打印数据就没有样式了;

这是因为打印插件中引入css样式的方式是http://ip:port/projectName/css/bootstrap-table.css的形式;//ip:ip地址,port:端口号,projectName:项目名,css:css文件夹

例如:printThis.js中的代码: baseURL = document.location.protocol + '//' + document.location.host;

不要在本地直接打开测试兼容性,css样式不会被引入;


bootstrapTable printThis打印插件 具体怎么用就不说了,可以参考这个地址: http://www.cnblogs.com/gzcblogs/p/7799621.html

但是你会发现,打印数据的样式怎么也加不上,解决方式用两种:

第一种:(推荐此种方式):

① 修改printThis.js 的 importCSS ,属性值设为 false; 例如

// defaults
    $.fn.printThis.defaults = {
        debug: false,           // show the iframe for debugging
        importCSS: false,        // import parent page css
        importStyle: false,     // import style tags
        printContainer: true,   // print outer container/$.selector
        loadCSS: "",            // load an additional css file - load multiple stylesheets with an array []
        pageTitle: "",          // add title to print page
        removeInline: false,    // remove all inline styles
        printDelay: 333,        // variable print delay
        header: null,           // prefix to html
        footer: null,           // postfix to html
        formValues: true,       // preserve input/form values
        canvas: false,          // copy canvas content (experimental)
        base: false,            // preserve the BASE tag, or accept a string for the URL
        doctypeString: '<!DOCTYPE html>', // html doctype
        removeScripts: false,   // remove script tags before appending
        copyTagClasses: false   // copy classes from the html & body tag
    };

    ②.调用过程如下:(importCSS 属性不要写 或 赋值为 false,不要设置为true,一定要有loadCSS属性)

function printThis(){    //TestBootStrap11 为项目名(记得要加上)

$("#table").printThis({  
           debug: false,  
         
// importCSS:fase,
           importStyle: false,  
           printContainer: true,  
     
     loadCSS: ["TestBootStrap11/css/bootstrap-table.css","TestBootStrap11/css/bootstrap.min.css"],
           pageTitle: "洗衣机统计表",  
           printDelay: 333,
           formValues: false
        });
};

总结:printThis.js 给了两种打印数据带样式的方式:importCSS 和 loadCSS其中importCSS 方式添加样式的引用路径中少了以及项目名

loadCSS是自己添加路径,我在相对路径的基础上加上了项目名(TestBootStrap11,就OK了。



第二种方式就不多说了,指点一下:在printThis.js 找到 它引用的路径,添加上项目名就行了,

获取项目名的方法:

function getProjectName(){
var pathName = document.location.pathname;
return pathName.substring(0,pathName.substr(1).indexOf('/')+1);
}

这时候importCSS 可以用了,printThis.js中的默认样式还改为true;

本人认为在设置属性时二者选其一,都选浪费性能。

经过我对各种前端数据表格的使用,复杂的表头,行分组,小计,合计,导出,打印等功能的实现,推荐使用 bootstrap table 框架



おすすめ

転載: blog.csdn.net/qwer123456u/article/details/78721603