使用javascript结合两个html表内容(部分表)并下载为png和csv

时间:2017-05-16 18:39:28

标签: javascript jquery html csv html2canvas

我使用了$('#xxx')。html()并使用了变量,如var b =''+ $('#xxx')。html()使用了我需要的内容的id。 + $('#yyy')。html()+。并认为将p下载为png和csv。

<div id="table_parent_div">
<div class="table_header">
    <table class="data_table">
        <thead>
            <tr style="height: 40px;">
                <th class="header">KPI Name</th>
                <th class="header">May-2016</th>
                <th class="header">Jun-2016</th>
                <th class="header">Jul-2016</th>
                <th class="header">Aug-2016</th>
                <th class="header">Sep-2016</th>
                <th class="header">Oct-2016</th>
                <th class="header">Nov-2016</th>
                <th class="header">Dec-2016</th>
                <th class="header">Jan-2017</th>
                <th class="header">Feb-2017</th>
                <th class="header">Mar-2017</th>
                <th class="header">Apr-2017</th>
                <th class="header">May-2017</th>
            </tr>
        </thead>
    </table>
</div>
<div class="table_body">
    <table class="data_table_body">
        <tbody id="category_name_0">
            <tr>
                <td class=" name ">category name 0</td>
                <td class=" name ">149.7 </td>
                <td class=" name ">149.57 </td>
                <td class=" name ">140.6 </td>
                <td class=" name ">154.82 </td>
                <td class=" name ">158.12 </td>
                <td class=" name ">168.71 </td>
                <td class=" name ">161.11 </td>
                <td class=" name ">149.15 </td>
                <td class=" name">149.03 </td>
                <td class=" name">114.2 </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name1 </td>
                <td class=" sub_cat">35.22 </td>
                <td class=" sub_cat">37.16 </td>
                <td class=" sub_cat">26.03 </td>
                <td class=" sub_cat">38.96 </td>
                <td class=" sub_cat">35.22 </td>
                <td class=" sub_cat">49.99 </td>
                <td class=" sub_cat">43.24 </td>
                <td class=" sub_cat">39.66 </td>
                <td class=" sub_cat">40.61 </td>
                <td class=" sub_cat">32.2 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name3 </td>
                <td class=" sub_cat">34.43 </td>
                <td class=" sub_cat">30.88 </td>
                <td class=" sub_cat">28.75 </td>
                <td class=" sub_cat">29.54 </td>
                <td class=" sub_cat">33.04 </td>
                <td class=" sub_cat">33.46 </td>
                <td class=" sub_cat">28.54 </td>
                <td class=" sub_cat">30.41 </td>
                <td class=" sub_cat">22.78 </td>
                <td class=" sub_cat">17.93 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name2 </td>
                <td class=" sub_cat">80.06 </td>
                <td class=" sub_cat">81.52 </td>
                <td class=" sub_cat">85.83 </td>
                <td class=" sub_cat">86.31 </td>
                <td class=" sub_cat">89.85 </td>
                <td class=" sub_cat">85.26 </td>
                <td class=" sub_cat">89.33 </td>
                <td class=" sub_cat">79.08 </td>
                <td class=" sub_cat">85.64 </td>
                <td class=" sub_cat">64.07 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
        </tbody>
        <tbody id="category_name_1">
            <tr>
                <td class=" name ">category name 1</td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">3.72 </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name1 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">2.23 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                </tr>
            <tr>
                <td class=" sub_cat ">sample_name5 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">1.86 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name4 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">0.37 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>

                <td class=" sub_cat">- </td>
            </tr>
            <tr>
                <td class=" sub_cat">sample_name3 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">0.78 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name2 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">0.7 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
        </tbody>
        <tbody id="category_name_2">
            <tr>
                <td class=" name ">category name 2</td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">74.51 </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
                <td class=" name">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name4 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">73.55 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
            <tr>
                <td class=" sub_cat ">sample_name2 </td>
                <td class=" sub_cat ">- </td>
                <td class=" sub_cat ">- </td>
                <td class=" sub_cat ">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">0.96 </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
                <td class=" sub_cat">- </td>
            </tr>
        </tbody>
    </table>
</div>

在这里,我需要结合thead和tbody(对于ex:tbody,id =“category_name_1”)并将它们下载为png和csv。

0 个答案:

没有答案