到目前为止,这是我的HTML,我不确定该怎么做= /我想要做的是呈现通过选中复选框填充的数据。使用最后一个函数填充新数组。然后我希望能够在html文件中使用javascript呈现新数组。
我需要的是一些代码放入我的html文件以使用最后一个函数(添加项目)我需要它来将新数组打印到屏幕上。
这是我用来在屏幕上打印第一个数组的html,虽然它似乎不适用于新的。
<script type="text/javascript">
for(x=0; x<=computer.length-1; x++) {
document.write("<tr id='"+x+"'><td><label><input type='checkbox'name='item' value='"+x+"'/> "+computer[x].split(",")[0]+"</label></td><td>"+computer[x].split(",")[1]+"</td><td> <input name='qty' id='qty' type='textbox' value='0' onchange='qtychange(document.myform.qty);'/> </td><td>"+computer[x].split(",")[2]+"</td></tr>");
}
</script>
这是我的所有Javascript
var computer = new Array();
var selected = new Array();
computer[0] = "10001, Nvidia Geforce GTX 690, $1200";
computer[1] = "10002, Raedon HD 7950, $450";
computer[2] = "20001, Ivy Bridge i7 3770, $400";
computer[3] = "20002, Ivy Bridge i7 3770k, $420";
computer[4] = "20003, Sandy Bridge i7 2700k, $340";
computer[5] = "20004, Bulldozer FX-8150, $270";
computer[6] = "30001, Antec eleven-hundred, $120";
computer[7] = "30002, Coolermaster HAF-X, $170";
computer[8] = "30003, Antec three-hundred, $50";
computer[9] = "30004, Corsair 550D, $160";
computer[10] = "40001, INTEL-ASrock fatal1ty Z77 Professional Motherboard, $250";
computer[11] = "40002, INTEL-ASrock Z77 extreme9 Motherboard, $350";
computer[12] = "40003, AMD-ASrock fatal1ty 990FX Professional Motherboard, $240";
computer[13] = "40004, AMD-ASUS Sabertooth 990FX Motherboard, $260";
function check(field) {
for (i = 0; i <= field.length - 1; i++) {
field[i].checked = true;
}
}
function uncheck(field) {
for (i = 0; i <= field.length - 1; i++) {
field[i].checked = false;
}
}
function addItems(field) {
for (i = 0; i <= field.length - 1; i++) {
if (field[i].checked == true) {
if (computer[i] != null) {
selected.push(computer[i]);
}
}
}
}