动态加载JS
function loadScript(scriptUrl, callback) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptUrl;
document.head.appendChild(script);
callback();
}
loadScript("https://code.jquery.com/jquery-3.3.1.min.js", function() {
console.log("loading script");
setTimeout(function () {
console.log("loading done");
//部分DIV 变为整个页面
$("body").html($('#sbo-rt-content').wrap('<p/>').parent().html());
//动态添加CSS
$(document.head).append(`<style>
@media print {
#sbo-rt-content {
background-color: white;
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
margin: 0;
padding: 15px;
font-size: 14px;
line-height: 18px;
}
}
</style>`);
//打印
window.print();
}, 3000);
});