Как я могу переместить данные строки таблицы в шаблон HTML страницы? - PullRequest
0 голосов
/ 28 декабря 2018

Мне нужно html-файлы. 1-ая - это таблица с ботоном в последнем столбце, 2-ая - это html-файл с изображением, поэтому мне нужно щелкнуть строку таблицы и напечатать это значение через второй html-файл, это сертификат.со значениями имеет имя и время хронометра, конечной целью является печать в pdf, но сейчас я пытаюсь переместить данные строки таблицы в сертификат.

большое спасибо за помощь

это таккод, который я пытаюсь использовать в 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>

1 Ответ

0 голосов
/ 29 декабря 2018

Вот один из способов сделать это.

Измените ваш табличный скрипт следующим образом:

<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>

Затем, на вашей второй HTML-странице, загрузите jQuery, и вы можете получить такие значения, какthis:

<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>

Если серверу нужно проанализировать файл (потому что ему нужен ключ или что-то, что есть только у сервера), то вам нужно отправить данные на него с помощью POST, как Вы можете увидеть здесь .

Надеюсь, это поможет.

...