我需要將大量PHP生成的HTML(5000個div元素)附加到文檔片段並將其附加到頁面主體。將PHP生成的HTML附加到文檔片段中
例HTML(這僅僅是StackOverflow的源的一部分,但它是相似的):
<div itemscope itemtype="http://schema.org/Article">
<link itemprop="image" href="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png">
<div id="question-header">
<h1 itemprop="name"><a href="https://stackoverflow.com/questions/4287357/access-php-variable-in-javascript" class="question-hyperlink">Access PHP variable in JavaScript [duplicate]</a></h1>
</div>
<div id="mainbar">
<div class="question" data-questionid="4287357" id="question">
<div class="everyonelovesstackoverflow" id="adzerk1">
</div>
<table>
<tr>
<td class="votecell">
<div class="vote">
<input type="hidden" value="4287357">
<a class="vote-up-off" title="This question shows research effort; it is useful and clear (click again to undo)">up vote</a>
<span class="vote-count-post ">2</span>
<a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful (click again to undo)">down vote</a>
<a class="star-off" href="#" title="This is a favorite question (click again to undo)">favorite</a>
<div class="favoritecount"><b>1</b></div>
</div>
我已經打破了問題分爲2點較小的問題:在Javascript
- 商店PHP可變:
var tmp = "<?php Print($DOM); ?>";
- 將HTML添加到文檔片段中(查看this但它是關於其他內容)
我該如何得到這個工作?
在PHP中存儲PHP變量:http://php.net/manual/en/function.json-encode.php – Saturnix 2013-04-23 00:24:07
您如何使用PHP生成HTML代碼並將其打印出來?你爲什麼不能那樣做? – Saturnix 2013-04-23 00:25:25
這就是我最初一直在做的事情,但我想通過使用文檔片段來了解是否有性能提升。目前,加載需要5秒鐘的時間,因爲我正在經歷多個循環並將HTML打印出來。由於有超過5000個div,不得不經常抓取數據和繪畫似乎會大大減緩它的速度。 – theintellects 2013-04-23 00:34:01