无法打印网格内部的图像控件

时间:2014-01-13 11:31:46

标签: jquery asp.net image

这是jquery代码::

<script type="text/javascript">
    function PrintElem(elem) {
        Popup($(elem).html());
    }

    function Popup(data) {
        alert(document.getElementById('<%=imgphoto.ClientID%>').src);
        var mywindow = window.open('', 'Customer Details', 'height=400,width=600');
        mywindow.document.write('<html><head><title>Customer Details</title>');
        mywindow.document.write('</head><body >');

        mywindow.document.write(data);
        mywindow.document.write('</body></html>');
        mywindow.print();
        mywindow.close();
        return true;
        }
    </script>

这是我的源代码::

<div id="mydiv">
        <table style="width: 100%">
            <tr>
                <td colspan="2" style="font-size: large">
                    Customer Document Details
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <b></b>
                </td>
            </tr>
            <tr>
                <td style="height: 20px; width: 140px">
                    <b>Photo</b>
                </td>
                <td style="font-weight: 700">
                    <asp:Image ID="imgphoto" runat="server" AlternateText="Image Not Available" class="imgresize"
                        ForeColor="Red" Height="85px" ImageUrl="~/Images/Empty.png" Width="109px" />
                </td>
            </tr>
         </table>
    </div>
<asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintElem('#mydiv')"
        CausesValidation="False" />

我的问题::

我正在尝试在按钮div tag上打印OnClientClick="PrintElem('#mydiv')"的所有内容,但我获取除了Image之外的div标签的所有内容。所以请在打印页面时帮助我获取图像控制。< / p>

1 个答案:

答案 0 :(得分:0)

我修改了你的代码

<强>脚本

<script type="text/javascript">
        function PrintElem(elem) {
            Popup($(elem).html());
        }

        function Popup(data) {
            alert(document.getElementById('<%=imgphoto.ClientID%>').src);
            var mywindow = window.open('', 'Customer Details', 'height=400,width=600');
            mywindow.document.write(data);

            mywindow.print();
            mywindow.close();
            return true;
        }
    </script>

源代码:

<div id="mydiv">
        <table style="width: 100%">
            <tr>
                <td colspan="2" style="font-size: large">
                    Customer Document Details
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <b></b>
                </td>
            </tr>
            <tr>
                <td style="height: 20px; width: 140px">
                    <b>Photo</b>
                </td>
                <td style="font-weight: 700">
                    <asp:Image ID="imgphoto" runat="server" AlternateText="Image Not Available" class="imgresize"
                        ForeColor="Red" Height="85px" ImageUrl="Desert.jpg" Width="109px" />
                </td>
            </tr>
        </table>
    </div>
    <asp:Button ID="btnPrint" runat="server" Text="Print" OnClientClick="PrintElem('#mydiv')"
        CausesValidation="False" />

完美地工作。

我上面的代码没有用。请参考以下网址中的另一个 http://www.aspdotnet-suresh.com/2013/08/jquery-print-div-content-with-css-using.html” 它也在工作