我有这个块:
document.write('<div class="sz1of4 unit sm-quad">
<ul>
<li><a href="/shop_pos/pos_hardware/pos_computer" alt="POS Computer">POS Computer</a></li>
<li><a href="/shop_pos/pos_hardware/touch_monitor" alt="Touch Monitor">Touch Monitor</a></li>
<li><a href="/shop_pos/pos_hardware/receipt_printer" alt="POS Receipt Printer">POS Receipt Printer</a></li>
<li><a href="/shop_pos/pos_hardware/cash_drawers" alt="Cash Drawer">Cash Drawer</a></li>
<li><a href="/shop_pos/pos_hardware/pole_display" alt="Pole Display">Pole Display</a></li>
<li><a href="/shop_pos/pos_hardware/pos_accessories/88003_002" alt="Fingerprint Scanner">Fingerprint Scanner</a></li>
<li><a href="/shop_pos/pos_hardware/pos_computer/fz43_mc2_ald" alt="Mobile POS">Mobile POS</a></li>
<li><a href="/shop_pos/pos_hardware/network/mbr900" alt="3G Backup">3G Backup</a></li>
</ul>
</div>
<div class="sz1of4 unit sm-quad">
<ul>
<li><a href="/restaurant_pos_software" alt="Restaurant POS Software">Restaurant POS Software</a></li>
<li><a href="/software/aldelo/easy.html" alt="Easy To Use">Easy To Use</a></li>
<li><a href="/software/aldelo/bar_tabs.html" alt="Bar Tabs">Bar Tabs</a></li>
<li><a href="/software/aldelo/multilingual.html" alt="Multilingual Capable">Multilingual Capable</a></li>
<li><a href="/shop_pos/point-of-sale-software/413614" alt="Quickbooks Integration">Quickbooks Integration</a></li>
<li><a href="/shop_pos/point-of-sale-software/liquor_monitor" alt="Liquor Monitor Capable">Liquor Monitor Capable</a></li>
<li><a href="/software/aldelo/reservations.html" alt="Reservations">Reservations</a></li>
<li><a href="/software/aldelo/training_mode.html" alt="Training Mode">Training Mode</a></li>
</ul>
</div>
<div class="sz1of4 unit sm-quad">
<ul>
<li><a href="/mercury/" alt="Integrated Payments">Integrated Payments</a></li>
<li><a href="http://www.mercurypay.com/products.htm" alt="Fast Transactions">Fast Transactions</a></li>
<li><a href="http://www.mercurypay.com/merchant-reports.htm" alt="Reduced Errors">Reduced Errors</a></li>
<li><a href="http://www.mercurypay.com/products.htm" alt="Secure Transactions">Secure Transactions</a></li>
<li><a href="http://www.mercurypay.com/gift-cards.htm" alt="Fee Free Gift Cards">Fee Free Gift Cards</a></li>
<li><a href="/mercury/" alt="Free 24/7 Support">Free 24/7 Support</a></li>
<li><a href="http://www.mercurypay.com/merchants.htm" alt="Competetive Pricing">Competetive Pricing</a></li>
<li><a href="/mercury/" alt="Get a Free Quote">Get a Free Quote</a></li>
</ul>
</div>
<div class="sz1of4 unit sm-quad lastUnit">
<ul>
<li><a href="http://posnation.com" alt="Free Expert Consultations">Free Expert Consultations</a></li>
<li><a href="/pos_systems/" alt="Plug & Play POS System">Plug & Play POS System</a></li>
<li><a href="/pos_support_page" alt="24/7 Support">24/7 Support</a></li>
<li><a href="/pos_live_time" alt="Live Training">Live Training</a></li>
<li><a href="/training_dvds" alt="DVD Training">DVD Training</a></li>
<li><a href="/pos_urgent" alt="Urgent Care Warranty">Urgent Care Warranty</a></li>
<li><a href="/shop_pos/pos_services" alt="Onsite Installation">Onsite Installation</a></li>
<li><a href="/shop_pos/" alt="Local Touch - Online Prices">Local Touch - Online Prices</a></li>
</ul>
</div>');
...没有用document.write显示,但是这个:
document.write('Hey there');
......运作良好。有什么区别,为什么大块不起作用?
答案 0 :(得分:8)
多行字符串必须以\
结束每一行。
以下是更新后的小提琴:http://jsfiddle.net/pSpHb/1/
答案 1 :(得分:3)
JavaScript不支持multiline strings,这就是为什么该示例不适合您。
最好使用像createDocumentFragment
之类的东西来到达你想去的地方。
答案 2 :(得分:0)
因为如果这些行不以'+ [new line]'
尝试这个
document.write('<div class="sz1of4 unit sm-quad">'+
'<ul>'+
' <li><a href="/shop_pos/pos_hardware/pos_computer" alt="POS Computer">POS Computer</a></li>'+
' <li><a href="/shop_pos/pos_hardware/touch_monitor" alt="Touch Monitor">Touch Monitor</a></li>'+
'<li><a href="/shop_pos/pos_hardware/receipt_printer" alt="POS Receipt Printer">POS Receipt Printer</a></li>'+
'<li><a href="/shop_pos/pos_hardware/cash_drawers" alt="Cash Drawer">Cash Drawer</a></li>'+
'<li><a href="/shop_pos/pos_hardware/pole_display" alt="Pole Display">Pole Display</a></li>'+
' <li><a href="/shop_pos/pos_hardware/pos_accessories/88003_002" alt="Fingerprint Scanner">Fingerprint Scanner</a></li>'+
' <li><a href="/shop_pos/pos_hardware/pos_computer/fz43_mc2_ald" alt="Mobile POS">Mobile POS</a></li>'+
' <li><a href="/shop_pos/pos_hardware/network/mbr900" alt="3G Backup">3G Backup</a></li>'+
'</ul>'+
'</div>'+
'<div class="sz1of4 unit sm-quad">'+
' <ul>'+
' <li><a href="/restaurant_pos_software" alt="Restaurant POS Software">Restaurant POS Software</a></li>'+
' <li><a href="/software/aldelo/easy.html" alt="Easy To Use">Easy To Use</a></li>'+
' <li><a href="/software/aldelo/bar_tabs.html" alt="Bar Tabs">Bar Tabs</a></li>'+
' <li><a href="/software/aldelo/multilingual.html" alt="Multilingual Capable">Multilingual Capable</a></li>'+
' <li><a href="/shop_pos/point-of-sale-software/413614" alt="Quickbooks Integration">Quickbooks Integration</a></li>'+
' <li><a href="/shop_pos/point-of-sale-software/liquor_monitor" alt="Liquor Monitor Capable">Liquor Monitor Capable</a></li>'+
' <li><a href="/software/aldelo/reservations.html" alt="Reservations">Reservations</a></li>'+
' <li><a href="/software/aldelo/training_mode.html" alt="Training Mode">Training Mode</a></li>'+
' </ul>'+
'</div>'+
'<div class="sz1of4 unit sm-quad">'+
' <ul>'+
' <li><a href="/mercury/" alt="Integrated Payments">Integrated Payments</a></li>'+
' <li><a href="http://www.mercurypay.com/products.htm" alt="Fast Transactions">Fast Transactions</a></li>'+
' <li><a href="http://www.mercurypay.com/merchant-reports.htm" alt="Reduced Errors">Reduced Errors</a></li>'+
' <li><a href="http://www.mercurypay.com/products.htm" alt="Secure Transactions">Secure Transactions</a></li>'+
' <li><a href="http://www.mercurypay.com/gift-cards.htm" alt="Fee Free Gift Cards">Fee Free Gift Cards</a></li>'+
' <li><a href="/mercury/" alt="Free 24/7 Support">Free 24/7 Support</a></li>'+
' <li><a href="http://www.mercurypay.com/merchants.htm" alt="Competetive Pricing">Competetive Pricing</a></li>'+
' <li><a href="/mercury/" alt="Get a Free Quote">Get a Free Quote</a></li>'+
'</ul>'+
'</div>'+
'<div class="sz1of4 unit sm-quad lastUnit">'+
' <ul>'+
' <li><a href="http://posnation.com" alt="Free Expert Consultations">Free Expert Consultations</a></li>'+
' <li><a href="/pos_systems/" alt="Plug & Play POS System">Plug & Play POS System</a></li>'+
' <li><a href="/pos_support_page" alt="24/7 Support">24/7 Support</a></li>'+
' <li><a href="/pos_live_time" alt="Live Training">Live Training</a></li>'+
'<li><a href="/training_dvds" alt="DVD Training">DVD Training</a></li>'+
' <li><a href="/pos_urgent" alt="Urgent Care Warranty">Urgent Care Warranty</a></li>'+
' <li><a href="/shop_pos/pos_services" alt="Onsite Installation">Onsite Installation</a></li>'+
' <li><a href="/shop_pos/" alt="Local Touch - Online Prices">Local Touch - Online Prices</a></li>'+
'</ul>'+
'</div>');
答案 3 :(得分:0)
第一个在字符串中间有一个(文字)新行。你不能在JS中做到这一点。