【发布时间】:2011-06-30 20:34:20
【问题描述】:
我正在尝试使用以下方法将在字符串中构建的下表附加到我页面上的 div 中:
var table =
'<table data-custom="3963770" id="table" cellpadding="3" cellspacing="5"
valign="top" width="995px" border="3" bordercolor="#83725B">
<th height="50" colspan="2">Company Name</th>
<th height="50" colspan="3">Esco Number</th>
<th height="50" colspan="1">Province</th>
<th height="50">Sector</th>
<th height="50">Technology</th>
<th height="50" colspan="2">Status</th>
<tr>
<td colspan="2">3H Envirostrategies cc</td>
<td colspan="3">11059420</td>
<td>Gauteng, KZN, Western Cape, Mpumalanga, Free State,
Eastern Cape</td>
<td>
<select id="mainSectors0">
<option>Commercial</option>
</select>
</td>
<td>
<select id="mainTechs0">
<option>Project Management</option>
</select>
</td>
<td colspan="2">Active</td>
</tr>
<tr>
<td style="border: none;" colspan="5">
<div data-custom="contact_info" style="display:inline;"><u>Contact information</u></div>
</td>
</tr>
<tbody data-custom="place_holder">
</tbody>
</table>';
我有一个 div 标签:
<div id="table"></div>
然后我尝试使用它来将表格添加到 div:
$(table).appendTo($('#table'));
// I've tried $("#table").append(table); but no luck.
它在除 IE 6+ 之外的所有其他浏览器中都能正常工作。有人知道解决方法吗,或者我做错了什么?
提前致谢。
【问题讨论】:
-
Javascript 对多行字符串非常敏感,我不会依赖它们在浏览器中被接受。尝试使用 var table = "
"
-
在 IE 中到底发生了什么?错误?
-
@Pointy 在任何 IE 浏览器中都没有发生任何事情......只是空白,@minikomi 我在上面格式化了它以提高可读性,它都在代码中的一行
-
你还想要原版吗?
标签: javascript jquery