开发者

Why is the data I am printing not in a table format

This is my program .when i submit the print button i can print the datas but they are not aligned in the table formatthe format in which i need the print to be...How can i print in the correct format

<html>
<head>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script> 
<script type="text/javascript">

    function PrintElem(elem)
    {   
        //alert('ddd');
        Popup($(elem).text());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'mydiv', 'height=400,width=600');
        mywindow.document.write('<html><head><title>my div</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');
        mywindow.document.close();
        mywindow.print();
        return true;
    }

</script>
</head>
<body>

<div id="mydiv">
   <table width="200" border="1">
  <tr>
    <td>sss</td>
    <td>sssss;</td>
    <td>snssbsp;</td>
  </tr>
  <tr>
    <td>ssss;</td>
    <td>sssnbsp;</td>
    <td>snbsp;</td>
  </tr>
  <tr>
    <td>snbsp;</td>
    <td>snbsp;</td>
    <td>snbsp;</td>
  </tr>
</table开发者_StackOverflow>

</div>


<input type="button" value="Print Div" onClick="PrintElem('#mydiv')" />

</body>
</html>


You’re calling the text method on your element, which returns the plain text content of the element with any HTML tags removed. Try this instead:

function PrintElem (elem)
{
   Popup($(elem).html());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜