繁体   English   中英

我调用javascript函数进行打印但不起作用

[英]I call a javascript function for print but doesn't work

我使用下面的代码从页面打印但不起作用(意味着当我点击打印按钮时没有任何反应)。 该功能不会调用

 <script type="text/javascript">
        function printing() {
            window.print();
        }
    </script>

protected void print_Click(object sender, EventArgs e)
{
    btnPrint.Attributes.Add("onclick", "return printing()");
}

试试这种方式:

<asp:Button ID="print" runat="server" Text="Print" OnClientClick="javascript:window.print();" />

在page_load事件中添加attributebind javascript event ,以便在单击打印按钮以打印页面之前bind javascript。

private void Page_Load(object sender, System.EventArgs e)
{
    btnPrint.Attributes.Add("onclick", "return printing()");
    //Your code here.
}

当用户单击该按钮时,您将添加一个属性,而不是调用printing()函数。

您应该将OnClientClick属性添加到按钮html中的按钮,如下所示:

<asp:button OnClientClick="return printing" ....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM