简体   繁体   English

从Java脚本将数组加载到网页

[英]Loading an Array from Java Script into Web page

I have included a fiddle here: jsfiddle.net/LgE3N 我在这里包括了一个小提琴: jsfiddle.net/LgE3N

I have a series of arrays in a javascript file that I need to import into an web page. 我需要导入到网页中的javascript文件中包含一系列数组。 I seem to be able to work with the arrays in the script and have been able to output totals of numbers into the page, however, I do not seem to be able to figure out how to print the entire list into the web page. 我似乎能够使用脚本中的数组,并且能够将总数输出到页面中,但是,我似乎无法弄清楚如何将整个列表打印到网页中。

    window.onload = function ()
    {
$("#contributions").html (totalContributions.toFixed(2));
$("#amount").html (totalContributors);  

var dateString = "";
for (var j = 0; j < date.length; j++)
{
    dateString += date[j];
    $("#dateArray").html (dateString);
}
    }

.

    <div id="data_list">
    <table rules="rows" cellspacing='0'>
        <thead>
            <tr>
                <th>Date</th>    
                <th>Amount</th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Address</th>
            </tr>
            <td>
                <p>dateArray</p>
                <id "dateArray">
            </td>
            <td>
                <p>amountArray</p>
            </td>
            <td>

This isn't really hard, you need a loop that returns each row and append it to the table. 这并不难,您需要一个循环,该循环返回每一行并将其附加到表中。

var count = firstName.length, sum = 0;

for (var i = 0; i < count; i++) {
    sum += parseFloat(amount[i]);
    html = '<tr><td>'+ date[i] +'</td><td>'+ amount[i] +'</td><td>'+ firstName[i] +'</td><td>'+ lastName[i] +'</td><td><p>'+ street[i] +'<br>'+ city[i] +' '+ state[i] +' '+ zip[i] +'</p></td></tr>';
    $('#data').append(html);
};

$('#contributions').html(count);
$('#amount').html(sum);

DEMO: http://jsfiddle.net/8XvQw/ 演示: http : //jsfiddle.net/8XvQw/

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

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