简体   繁体   English

如何将表格行数据移动到html页面模板?

[英]how can i move table row data to html page template?

i have to html files 1st is a table with a boton in the last column, the 2nd is a html file with an image so i need to clic the table row and print this values over the secont html file, is a certificate with values has name and chronometer time, the finale objetive is to print in pdf but now i am trying to move table row data to the certificate. 我必须html文件1st是在最后一列中带有boton的表,2nd是带有图像的html文件,所以我需要单击表行并在secont html文件上打印此值,是具有值的证书名称和天文台时间,结局是用pdf打印,但现在我正尝试将表行数据移至证书。

thnaks a lot for help 非常想得到帮助

this si the code i try on firts html file: 这是我尝试启动HTML文件的代码:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>

<script>
    //  function myFunction() {
    //    var myWindow = window.open("", "", "width=600,height=400");
    //   myWindow.document.write("valores+=$(this).html()+"\n");
    //   var valores="";
    //  $(this).parents("tr").find("td").each(function(){
    //               valores+=$(this).html()+"\n";
    //                                                  });
    //                              });

    $(document).ready(function() {
        $(".boton").click(function() {

            var myWindow = window.open("cert.html", "_blank", "width=1090,height=860");
            var valores = "";

            // Obtenemos todos los valores contenidos en los <td> de la fila
            // seleccionada
            $(this).parents("tr").each(function() {
                valores += $(this).html() + "\n";
                //valores = valores + "</br></br>";
            });

            //  myWindow.document.write(valores+ "<body background='plantilla.png'/>");
            //       myWindow.document.write("<span class='green'>The score you entered is:"   + valores +   ".Your letter grade is: B!</span>");
                 myWindow.document.write(valores);

           // myWindow.document.write(valores);

            // alert(valores);
        });
    });
</script>

<style>
    myWindow {
        background-image: url("cedulalmma.jpg");
    }

    .boton {
        border: 1px solid #808080;
        cursor: pointer;
        padding: 2px 5px;
        color: white;
    }
</style>

<table border="1" cellspacing="2" cellpadding="5">
    <tr>
        <td>val 1</td>
        <td>val 2</td>
        <td>val 3</td>
        <td class="boton"></td>
    </tr>
    <tr>
        <td>val 4</td>
        <td>val 5</td>
        <td>val 6</td>
        <td class="boton"></td>
    </tr>
    <tr>
        <td>val 7</td>
        <td>val 8</td>
        <td>val 9</td>
        <td class="boton"></td>
    </tr>
</table>

Here is one way to do it. 这是一种方法。

Modify your table script like this: 像这样修改表脚本:

<script>
    $(document).ready(function() {
      $(".boton").click(function() {
        var valores = "";
        // $(this).siblings() retrieves every adjacent td of the current one
        $(this).siblings().each(function() {
          valores += $(this).html() + "\n";
          //valores = valores + "</br></br>";
        });

        var myWindow = window.open("cert.html", "_blank", "width=1090,height=860");
        // Here You assing the values to a window property:
        myWindow.valores = valores;
      });
    });
</script>

Then, in your second HTML page, load jQuery and you could get the values like this: 然后,在第二个HTML页面中,加载jQuery,您将获得如下所示的值:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function() {
        // Here you can manipulate the however you like
        console.log(window.valores);
    });
</script>

If the server needs to parse the file (because it needs a key or something that only the server has), then You need to send the data to it using POST, as You can see here . 如果服务器需要解析文件(因为它需要密钥或只有服务器拥有的东西),那么您需要使用POST将数据发送给它,如您在此处看到的

Hope it helps. 希望能帮助到你。

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

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