Print when textarea has overflow

前端 未结 11 972
眼角桃花
眼角桃花 2020-12-04 23:59

I have a form with some text areas that allow a scroll bar when the text exceeds the text box. The user would like to be able to print the screen, and this text is not visib

11条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 00:32

    Adding onto Alan's answer above, if you have multiple instances of this problem on the same page, then you can use data-* attributes to handle all at once. Sample:

    var $printOnlyArr = $('.print-only');
    for (var i = 0; i < $printOnlyArr.length; i++) {
      var $printOnly = $($printOnlyArr[i]);
    	var textSource = $printOnly.data('textsource');
    	if (textSource) {
    	  $printOnly.text($("#" + textSource).val());
    	}
    }
    .print-only {
    	display: none;
    }
    
    @media print {
    	.print-only {
    		display: block;
    	}
    	.no-print {
    		display: none;
    	}
    }
    
    
    

提交回复
热议问题