asp.net - 使用asp.net打印学生准考证

标签 asp.net html css printing

我有一个网络应用程序,我们在其中的网页中收集学生数据。此 aspx 页面有一个“打印准考证”按钮,单击该按钮将打印准考证。我已经为卡片动态创建了一个 html 布局,并希望将其打印出来。如何实现?

最佳答案

这段代码可能会帮助你..

HTML代码:

 <div id="printarea">

//content you want to print
</div>

<input id="btnprint" type="button" onclick="PrintDiv()" value="Print" /></center>

Javascript 函数:

  <script type="text/javascript">

        function PrintDiv() {
            var divToPrint = document.getElementById('printarea');
            var popupWin = window.open('', '_blank', 'width=300,height=400,location=no,left=200px');
            popupWin.document.open();
            popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
            popupWin.document.close();
        }
     </script>

关于asp.net - 使用asp.net打印学生准考证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13577649/

相关文章:

c# - 方法 'btnLoginTest_Click' 没有重载需要 0 个参数

asp.net - 在CSS中对齐Div

html - 向上翻译该 div 时,如何去除该 div 下方的空白?

javascript - Axios 在单击按钮后调用时断开用户操作接下来发生的事情

html - 如何使用 CSS 为所有浏览器垂直居中 div 元素?

html - FF 中的 CSS 网格容器宽度计算错误

c# - 如何将一些数据写入excel文件(.xlsx)

c# - ASP.NET Core, EF Core 同时一对一和一对多

html - 区分 CSS 中的 Chrome 和 Safari 用户代理字符串(无 JavaScript)

html - css - 使 Logo 居中