原文地址:http://blog.sina.com.cn/s/blog_77ed775e01011ek7.html

一.用JS自带函数打印

<input >.....文本打印部分.....</div>

Query插件PrintArea完整方法如下:

    1. (function($) {
    2. var printAreaCount = 0;
    3. $.fn.printArea = function()
    4. {
    5. var ele = $(this);
    6. var idPrefix = "printArea_";
    7. removePrintArea( idPrefix + printAreaCount );
    8. printAreaCount++;
    9. var iframeId = idPrefix + printAreaCount;
    10. var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';
    11. iframe = document_createElement_x('IFRAME');
    12. $(iframe).attr({ style : iframeStyle,
    13. id    : iframeId
    14. });
    15. document.body.a(iframe);
    16. var doc = iframe.contentWindow.document;
    17. $(document).find("link")
    18. .filter(function(){
    19. return $(this).attr("rel").toLowerCase() == "stylesheet";
    20. })
    21. .each(function(){
    22. doc.write('<link type="text/css" rel="stylesheet" href="' +
    23. $(this).attr("href") + '" >');
    24. });
    25. doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
    26. doc.close();
    27. var frameWindow = iframe.contentWindow;
    28. frameWindow.close();
    29. frameWindow.focus();
    30. frameWindow.print();
    31. }
    32. var removePrintArea = function(id)
    33. {
    34. $( "iframe#" + id ).remove();
    35. };
    36. })(jQuery);

相关文章:

  • 2021-08-24
  • 2021-11-07
  • 2021-07-06
  • 2021-10-07
  • 2021-11-18
  • 2021-12-14
  • 2022-01-02
猜你喜欢
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2018-04-23
  • 2022-12-23
相关资源
相似解决方案