2.
bindData() {
$("input,select option").each(function() {
$(this).attr("value", $(this).val());
});
//搞定 type=checkbox,type=radio 选中状态
$("input[type=‘checkbox‘],input[type=‘radio‘]").each(function() {
if ($(this).prop("checked")){
$(this).attr("checked",true);
}
else{
$(this).removeAttr("checked");
}
});
// 搞定select选中状态
$("select option").each(function() {
if ($(this).attr("selected")) $(this).attr("selected", true);
else $(this).removeAttr("selected");
});
//搞定 textarea
$("textarea").each(function() {
$(this).html($(this).val());
});
},
3.
printContent() {
this.bindData();
const wpt = document.getElementById("panel");
const newContent = wpt.innerHTML;
const oldContent = document.body.innerHTML;
document.body.innerHTML = newContent;
document.getElementsByTagName("body")[0].style.zoom = 0.7; //缩放
window.print(); //打印方法
window.location.reload();
document.body.innerHTML = oldContent;
},