dongzuo7166 2018-06-02 10:18
浏览 47

Javascript - 打印完整的html块

I have this php code for write down list of html elements and dynamically change the text using an array. I want to accomplish this with a Javascript code, How do I do that?

    <?php
    $services = ["Storage", "network", "Virtual Machine", "server","firewall","firewall","users","backup"];
    $servicesName = ["Storage", "network", "Virtual Machine", "server","firewall","firewall","users","backup"];
$learnMore - ["Some Brief Description"];
    for ($i=0; $i < count($services); $i++) {
      $x = $i;
      echo "<div class='flexbox-item'>
        <div class='learnmore'>
        <img src='sourceimages/icons/speech/learnmore.png' alt='LearnMore'>
        <div>$learnMore</div>
        </div>
        <div class='maskshape'></div>
        <div class='shape'><img src='sourceimages/icons/services/$services[$i].png' alt='$servicesName[$i]'></div>
        <div class='number'><span>0".++$x."</span></div>
        <div class='title'><span>$servicesName[$i]</span></div>
      </div>";
  • 写回答

1条回答 默认 最新

  • dongraobei6719 2018-06-02 12:30
    关注

    You can print any html by below function. Pass html string in it as parameter.

    function print(htmlToPass) {
        var mywindow = window.open('', 'PRINT', 'height=400,width=600'); //create dummy window
        mywindow.document.write(htmlToPass); //write your html in it.
        mywindow.document.close(); // necessary for IE >= 10
        mywindow.focus(); // necessary for IE >= 10*/
        mywindow.print();
        mywindow.close();
        return true;
    }
    

    Ex. to call function.

    var htmltoprint = '<html><body><h1>anything you want to print</h1></body></html>'; print(htmltoprint);

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭