即时通讯使用jQuery的load()方法发送另一个html到我的网页。 正在加载的html包含Javascript生成的HTML。使用此功能加载HTML在ajax发送html + JS
林:
$(document).ready(function(){
$("img#links").click(function(){
$("div#content").load("links.html");
});
});
的links.html包含:
<h1 id="content">Links</h1>
<br>
<script>add_link("http://google.com");</script>
的add_link函数生成我的表:
var add_link = function(link) {
document.write("<table border=\"0\" width=\"100%\" height=\"50\" id=\"link\">");
document.write("<tr>");
document.write("<td width=\"50\"><img src=\"img/star.png\" /></td>");
document.write("<td><a href=\"" + link + "\"><div class=\"link\">" + link + "</div></a></td></tr></table>");
}
然而,当被调用而不是将js生成的代码写入网页时,它会被写入空白页co仅获取由JS生成的表。
考虑使用[javascript模板](http://stackoverflow.com/questions/7180582/templates-in-js)。 – moonwave99