例如,我想得到这样的东西:在document.write
中<form>
<table>
<tr>
<td align="right">Subtotal:</td>
<td align="left"><form name = "e" id ="e"><input type="text" id="subtotal" /></td>
</tr>
<tr>
<td align="right">Sales Tax:</td>
<td align="left"><form name = "f" id = "f"><input type="text" id="tax" /></td>
</tr>
<tr>
<td align="right">Total:</td>
<td align="left"><form name = "g" id = "g"><input type="text" id="total" /></td>
</tr>
</table>
</form>
我试过像
这样的东西document.write("paste whole code here");
没有工作。
答案 0 :(得分:1)
对于记录,我不鼓励使用document.write。但要回答你的问题,你只需要转义字符串中的换行符:
document.write('<form> \
<table> \
<tr> \
<td align="right">Subtotal:</td> \
<td align="left"><form name = "e" id ="e"><input type="text" id="subtotal" /></td> \
</tr> \
<tr> \
<td align="right">Sales Tax:</td> \
<td align="left"><form name = "f" id = "f"><input type="text" id="tax" /></td> \
</tr> \
<tr> \
<td align="right">Total:</td> \
<td align="left"><form name = "g" id = "g"><input type="text" id="total" /></td> \
</tr> \
</table> \
</form>');