我有一个包含一些PHP处理过的HTML的div。
和jsfiddle.net一样,我想要d div,显示从PHP创建的HTML,嵌套在另一个div中。它是一个创建HTML / CSS的程序,可供客户查看,现在我想让他们能够复制HTML / CSS代码供他们使用。
代码和可查看代码将位于同一网站上。
示例:
<div id="processed_html">
<div id="item" style="color:black; width:154px;"></div>
<div id="item" style="color:yellow; width:34px;"></div>
</div>
<div id="view_processed_client_code">
//Here i want all the code above to show as plain text
</div>
我在网上搜索过但找不到任何解决方案..
提前致谢! : - )
答案 0 :(得分:0)
我建议:
// references to the element holding the client-entered code:
var processed = document.getElementById('processed_html'),
// and the area to which it should be output:
output = document.getElementById('view_processed_client_code'),
// finding the text-property of the browser:
textProp = 'textContent' in document ? 'textContent' : 'innerText';
// setting the textual content of the output element to the innerHTML of the
// element holding the client-entered code:
output[textProp] = processed.innerHTML;
&#13;
#view_processed_client_code {
white-space: pre-wrap;
}
&#13;
<div id="processed_html">
<div class="item" style="color:black; width:154px;"></div>
<div class="item" style="color:yellow; width:34px;"></div>
</div>
<div id="view_processed_client_code">
//Here i want all the code above to show as plain text
</div>
&#13;