【发布时间】:2012-01-05 19:36:58
【问题描述】:
我正在使用 JQuery .get 方法从网页(第 1 页)中检索一些内容并将其显示在主页的 div 中。问题是检索到的内容包含一些 javascript 调用。内容正在显示,但 Javascript 方法未得到执行。 .js 文件在所有页面中都被引用,因此 main 中 js 的可用性不是问题。
这是主页中的代码。第 1 页的 URL 提供给 .get 函数:
$.get(url, function(response) {
var newContent = $(response).find("#right"); //Find the content section of the response
var contentWrapper = $("#wrap"); //Find the content-wrapper where we are supposed to change the content.
var oldContent = contentWrapper.find("#right"); //Find the old content which we should replace.
oldContent.replaceWith(newContent);
});
这是第1页#right(div)中的代码
Some html tags...
<p><script type="text/javascript">abc7();</script></p>
<p><script>s(30)</script></p>
Some html tags...
函数 abc7 和 s 在所有页面部分中引用的 .js(普通 javascript 文件)中可用
s(30) 应该显示一个大小为 30 的文本字段。
【问题讨论】:
-
我发现这个问题很相似:stackoverflow.com/questions/4619668/… 但是,那里提出的解决方案不符合我的目的。首先,我不确定 Page1 的响应中会调用什么函数。所以,我不能从我的 ajax 调用这些脚本。有出路吗?
标签: jquery javascript jquery-get