I'm new to web development, since 1-100, all the lines need to output to a new line. The code returns output to the final number:
var main = function () {for (var i = 1; i & lt; = 100; i ++) {$ ("result" ). Attached ("& lt; p & gt;") text (i). }}; $ (Document) .ready (main);
However, this does what I want to do:
var main = function () {var $ content; ($ Content = $ ("& lt; p & gt;"). Text (i); ("Results"). $ Attachments for (var i = 1; i & lt; = 100; i ++) ($ Content);}}; $ (document) .ready (main);
Why does the second solution work but not the first?
The issue with the first is that attachment ()
element ( .results
element) p
is not what was added to it, so you are updating the text property of .results
on each recurrence.
This also Keep in mind That is a relatively expensive operation in attachment ()
display, so that you can improve your speed of execution by adding your logic once again:
var Main = function (for {var content = ''; (var i = 1; i p & gt;' + I + '& lt ; / P & gt; ';} $ ("result"). Attachment (content);};
No comments:
Post a Comment