我正在尝试使用以下方法将以字符串形式构建的下表附加到页面上的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 id="table"></div>
然后,我尝试使用此表将表添加到div中:
$(table).appendTo($('#table'));
// I've tried $("#table").append(table); but no luck.
它在IE 6以外的所有其他浏览器中都可以正常工作.有人知道解决方法吗,或者我做错了什么?
提前致谢.
解决方法:
您的代码也对我有用,也适用于IE:http://jsfiddle.net/doktormolle/N5z5T/
您确定在table =’< table> ….< / table';之前使用var-keyword吗? 如果没有,则可能会破坏IE,请参阅以下相关主题:jQuery selector does not work in IE7/8