gpt4 book ai didi

javascript - jQuery append() 在 IE 中不起作用

转载 作者:行者123 更新时间:2023-11-29 10:53:00 25 4
gpt4 key购买 nike

我正在尝试使用以下方法将在字符串中构建的下表附加到我页面上的 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+ 之外的所有其他浏览器中都可以正常工作。有人知道解决方法吗,或者我做错了什么?

提前致谢。

最佳答案

您的代码适用于我,也适用于 IE:http://jsfiddle.net/doktormolle/N5z5T/

您确定在 table = '<table>....</table'; 之前使用了 var 关键字吗?

如果不是,这可能会破坏 IE,请参阅此相关主题:jQuery selector does not work in IE7/8

关于javascript - jQuery append() 在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6534431/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com