我想从我的 html 中获取文本并保留正确的格式,就像它在浏览器上的样子一样。
我要这个
CompanyName
CompanyAddress
Company Phone Number
1 Item1 7.00 0% 7.00
2 Item2 5.00 0% 5.00
TOTAL: 2
SUBTOTAL: 12.00
CASH: 12.00
我得到这个
CompanyName
CompanyAddress
Company Phone Number
1
Item1
7.00
0%
7.00
我的 HTML:
<div id="printPreview" class="interprise-popover-container">
<div class="interprise-popover-header popover-header">
<h1 class="title">Print Preview</h1>
<a class="popover-btn left-popover-btn btn-Cancel">Cancel</a>
<a class="popover-btn right-popover-btn btn-Done">Done</a>
</div>
<br class="clearfloat"/>
<div id="printPreviewBody" class="interprise-popover-content">
<div id="print-area">
<div id="print-header">
<h4><%= Company %></h4>
<h6><%= WarehouseAddress %></h6>
<h6><%= WarehouseCity %>, <%= WarehouseState %> <%= WarehousePostalCode %></h6>
<h6><%= PhoneNumber %></h6>
<h6>www.fairysales.com</h6>
<h5 style="margin-top: 5px;"><%= TransactionType %># <%= InvoiceCode %></h5>
</div>
<div id="print-barcode" style="margin:0 auto; "></div>
<span style="font-size: 12px;">Monday</span>
<div>
<table id="print-items" cellspacing="0" width="100%">
<tbody>
<tr>
<td align="right"> 1 </td>
<td align="left"> Item1<br></td>
<td align="right">12.00</td>
<td align="right">0%</td>
<td align="right"><div><abbr>12.00</abbr></div></td>
</tr>
</tbody>
</table>
</div>
<div id="print-total">
</div>
</div>
</div>
顺便说一句,我用
$("#print-header").text(); to extract the text from the div
更新:这里是 jsfiddle
我想要实现的实际上与结果相同,但采用文本格式,因此我可以将其作为字符串从 javascript 传递给目标 c。