打印功能

打印功能主要代码:

 function doprint(){

     //给要打印的区域赋值给body

      document.body.innerHTML = "要打印区域的innerHTML";

      //打印

      print();

 }

遇到的问题:

     1:动态赋值无法打印出来

       解决法案例子如下:

               绑定对应标签数据:

function bindData(){
   
	 //绑定type=checkbox,type=radio
	$("input[type='checkbox'],input[type='radio']").each(function(){
		if($(this).attr('checked'))
			$(this).attr('checked',true);
		else
			$(this).removeAttr('checked');
	});
	
   //绑定 type=text,checkbox,radio,select>option的值
	$("input,select option").each(function(){
		$(this).attr('value',$(this).val());
	});

	//select选中值
	$("select option").each(function(){
		if($(this).attr('selected'))
			$(this).attr('selected',true);
		else
			$(this).removeAttr('selected');
	});
	
}
	

   2:不能给table 中tbody.innHTML 赋值问题

      例如 :document.getElementById("tbody").innerHTML = ""

      解决方法:

       

function setTBodyInnerHTML(tbody,innerHtml){
      var div = document.createElement("div");
      div.innerHTML = '<table><tbody id="xxx">'+innerHtml+'</tbody></table>';
      tbody.parentNode.replaceChild(div.firstChild.firstChild,tbody);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值