0
4

2 回答 2

1

First, let's look at this line:

outputs[index] = (outputs[index] * 13) / 100;

What do you expect to happend here? Say index equals 0. outputs[0] == 'output1'. Your assignment is doing this (meta):

outputs[0] = ('output1' * 13) / 100;

You should revise this statement. As to your error, this should work for you:

document.getElementById(spans[index]).innerHtml = outputs[index];

EDIT: There are a lot of problems with your code. You need to fix your HTML (self-closed td and tr tags) and your JavaScript code (outputs values and innerHTML). Please see working example here: http://jsfiddle.net/pkRmC/2/

于 2013-02-07T14:38:56.793 回答
1

Use document.getElementById(spans[index]) if you don't want to select the (nonexisting) element with the literal id "'spans[index]'".

Btw, all your opening tags do incorrectly end with />, while it should be just >. Not sure how you did not get a big HTML parse error from that. The /> syntax is only permitted for self-closing elements such as hr, br, meta etc, and actually is only necessary in XHTML.

Also, your computation of outputs[index] * 13) / 100 does not make too much sense, since you are multiplying a string with the number 13 - which will result in NaN. Not sure what you wanted to achieve with that.

于 2013-02-07T14:39:54.793 回答