所以我試圖學習JavaScript,我想我有一個工作的JSON腳本與循環來抓取數據,但我無法弄清楚如何將數據追加到我的div 。在我弄清楚之後,我將重做它在jquery中(因爲我也試圖瞭解這一點)。在html中追加循環到div
比方說,我的div id爲#wrapper指定
for (var i = 0; i < providerlisting.length; i++) {
document.write('<div class="entry panel row"> \
<div class="large-4 columns first"> \
<div class="name">' + providerlisting[i].nametitle + '</div> \
<div class="specialty">' + providerlisting[i].caretype + '</div> \
<div class="peferred">' + providerlisting[i].preferredprovider + '</div> \
</div> \
<div class="large-3 columns second"> \
<div class="address">' + providerlisting[i].address1 + '<br /> \
' + providerlisting[i].address2 + '<br /> \
' + providerlisting[i].citystatezip + ' \
</div> \
</div> \
<div class="large-3 columns third"> \
<img src="' + providerlisting[i].coverage + '" alt="example"> \
</div> \
<div class="large-2 columns fourth"> \
<div class="status">' + providerlisting.status + '</div> \
<a data-dropdown="actionsMenu2" class="actions button small secondary round dropdown" href="#">Actions</a><br> \
<ul id="actionsMenu2" data-dropdown-content="" class="f-dropdown"> \
<li><a href="' + providerlisting[i].psn + '">Generate PSN</a></li> \
<li><a href="' + providerlisting[i].dcontact + '">Download Contact</a></li> \
<li><a href="' + providerlisting[i].save + '">Save to Provider List</a></li> \
<li><a href="' + providerlisting[i].rating + '">View Healthgrades Rating</a></li> \
</ul> \
</div> \
</div> \
')};
看到這個答案: http://stackoverflow.com/a/5677816/467133 祝你好運,學習jQuery! –
我的建議是刪除一切,重新開始,因爲這是一團糟!避免使用document.write和長的HTML字符串。 – adeneo
Adeneo,我正在嘗試學習javascript。請嘗試在將來建設性的。 – Chad